Skip to content

Commit

Permalink
Use reduce for more declarative summation
Browse files Browse the repository at this point in the history
  • Loading branch information
bespoyasov committed Jan 21, 2022
1 parent 1bf8fb1 commit 63cb891
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ function App() {

const _userId = user.name;
const products = cart.products;
let price = 0;
for (const p_i in products) {
price += products[p_i].price * products[p_i].count;
}
const price = products.reduce(
(tally, { price, count }) => tally + price * count,
0
);

let discount = 0;
switch (coupon) {
Expand Down

0 comments on commit 63cb891

Please sign in to comment.