Skip to content

Instantly share code, notes, and snippets.

@ar2zee
Created May 31, 2017 02:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Example of reduce function with array function
var orders = [
{amount: 250},
{amount: 300},
{amount: 350},
{amount: 400}
];
// var quintyty = orders.reduce (function(sum, order) { /*sum- first arguments our callback, order- iterated item */
// console.log('hello', sum , order);
// return sum + order.amount;
// }, 0); /* 0- it's starting point of our callback;( where we start counting)*/
var quintyty = orders.reduce((sum, order) => sum + order.amount , 0);
console.log(quintyty);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment