reworked sumseatprices with reduce

This commit is contained in:
zino
2021-05-16 23:11:35 +02:00
parent 1968fa0f74
commit 8c7d36d2f6

View File

@@ -103,10 +103,13 @@ function appendOption(inSelector: string, inArr: I.TypeBuyerTypeArr): void {
}
function sumSeatPrices(): string {
let overallPrice: number = 0;
return config.state.selectedSeatsArr.map(getSeatPrice)
.reduce((prev, curr) => prev + curr)
.toFixed(2);
}
config.state.selectedSeatsArr.forEach(arr => {
const seatID: string = arr[0];
function getSeatPrice(arr: string[]) {
const seatID: string = arr[0];
const buyertypeID: string = arr[1];
const selectedSeat: I.JSCSelectedSeat = config.state.selectedSeatsObj[seatID];
const pricescaleID: string = selectedSeat.data.seatsObj.id[0];
@@ -116,9 +119,8 @@ function sumSeatPrices(): string {
const seatPrice: number | undefined = XMLHelper.getPriceByBuyerTypeID(buyertypeID, pricescaleObj);
if (seatPrice)
overallPrice += seatPrice;
}
});
return seatPrice;
}
return overallPrice.toFixed(2);
}
return 0;
}