Created
May 31, 2017 02:18
-
-
Save ar2zee/21b874647d5a2b1c3c4a44860863c566 to your computer and use it in GitHub Desktop.
Example of reduce function with array function
This file contains 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
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