Last active
July 31, 2020 13:45
-
-
Save lsbyerley/709df4f38895a27a754eda47c22e6ce7 to your computer and use it in GitHub Desktop.
Calculate total of product prices in cart with reduce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.clear(); | |
const cart = [ | |
{price: 12, amount: 1}, | |
{price: 7.5, amount: 2}, | |
{price: 8, amount: 4} | |
]; | |
const total = [...cart].reduce((total, { amount, price }) => { | |
return (total += amount * price); | |
}, 0); | |
console.log(total); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment