aboutsummaryrefslogtreecommitdiff
path: root/src/components/Display
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-05-05 11:00:28 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-05-05 11:00:28 +0530
commit5b630590d7e2f803007911e22f24444aefef541d (patch)
tree21d0a567bd7fcf9db46d2035dbcd540a22fe2d86 /src/components/Display
parent499c54e8eb53cf49d8ddae68528eb3a8243101d2 (diff)
made the code less error prone and more oriented towards the functional paradigm
Diffstat (limited to 'src/components/Display')
-rw-r--r--src/components/Display/SummaryDisplay.js23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/components/Display/SummaryDisplay.js b/src/components/Display/SummaryDisplay.js
index 2f65e79..9b1ca6b 100644
--- a/src/components/Display/SummaryDisplay.js
+++ b/src/components/Display/SummaryDisplay.js
@@ -13,10 +13,12 @@ const getBasicSummary = (items) => {
let totalRawPrice = 0;
let totalQuantity = 0;
- for (let i = 0; i < items.length; i++) {
- totalRawPrice += items[i].TotalPrice;
- totalQuantity += items[i].Quantity
- }
+ items.some((i) => {
+ totalRawPrice += i.TotalPrice;
+ totalQuantity += i.Quantity;
+ return null;
+ }
+ )
return (
{
@@ -31,14 +33,17 @@ const getFullSummary = (items) => {
let totalDiscount = 0; // to be subtracted from totalRawPrice
let totalTax = 0;
- for (let i = 0; i < items.length; i++) {
- const itemTotalPrice = items[i].TotalPrice;
- const itemDiscount = (items[i].Discount / 100) * itemTotalPrice;
+ items.some((i) => {
+ const itemTotalPrice = i.TotalPrice;
+ const itemDiscount = (i.Discount / 100) * itemTotalPrice;
totalRawPrice += itemTotalPrice;
totalDiscount += itemDiscount;
- totalTax += (items[i].GST / 100) * (itemTotalPrice - itemDiscount);
- }
+ totalTax += (i.GST / 100) * (itemTotalPrice - itemDiscount);
+ return null;
+ })
+
+
const totalPriceAfterTax = (totalRawPrice - totalDiscount) + totalTax;
const totalRoundedOff = Math.abs(totalPriceAfterTax - Math.round(totalPriceAfterTax));