Skip to content

Instantly share code, notes, and snippets.

@arnonate
Created September 18, 2020 19:12
Show Gist options
  • Save arnonate/2ef9adfc1abfc86c0df53fb4e6abe210 to your computer and use it in GitHub Desktop.
Save arnonate/2ef9adfc1abfc86c0df53fb4e6abe210 to your computer and use it in GitHub Desktop.
// Reduce can be used to sum all products
const products = [{ price: 1 }, { price: 2 }, { price: 3 }, { price: 4 }];
function sumAllPrices(products) {
return products.reduce((sum, product) => sum + product.price, 0);
}
sumAllPrices(products); // 425
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment