reworked sumseatprices with reduce
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user