Created
July 17, 2018 13:46
-
-
Save adamgiese/1f601b588c8b3853ba4f523536ba446b to your computer and use it in GitHub Desktop.
Declarative Arrays: Naming Callback Parameters
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
const cart = [ | |
{ | |
name: 'Waterloo Sparkling Water', | |
quantity: 4, | |
price: 1, | |
}, | |
{ | |
name: 'High Brew Coffee', | |
quantity: 2, | |
price: 2, | |
}, | |
]; | |
const toTotal = (totalPrice, {quantity, price}) => | |
totalPrice + quantity * price; | |
const total = cart.reduce(toTotal, 0); | |
console.log(total); // 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment