From 8c7d36d2f6737889f59a338654d10aab356abeaf Mon Sep 17 00:00:00 2001 From: zino Date: Sun, 16 May 2021 23:11:35 +0200 Subject: [PATCH] reworked sumseatprices with reduce --- client/src/modules/cart.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/client/src/modules/cart.ts b/client/src/modules/cart.ts index a35c2f5..50a443a 100644 --- a/client/src/modules/cart.ts +++ b/client/src/modules/cart.ts @@ -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; +} \ No newline at end of file