Skip to content

Instantly share code, notes, and snippets.

@ar2zee
Created May 31, 2017 02:18
Show Gist options
  • Save ar2zee/21b874647d5a2b1c3c4a44860863c566 to your computer and use it in GitHub Desktop.
Save ar2zee/21b874647d5a2b1c3c4a44860863c566 to your computer and use it in GitHub Desktop.
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