Skip to content

Instantly share code, notes, and snippets.

@adamgiese
Created July 17, 2018 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamgiese/1f601b588c8b3853ba4f523536ba446b to your computer and use it in GitHub Desktop.
Save adamgiese/1f601b588c8b3853ba4f523536ba446b to your computer and use it in GitHub Desktop.
Declarative Arrays: Naming Callback Parameters
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