Skip to content

Instantly share code, notes, and snippets.

@shaunwallace
Created November 19, 2014 14:40
Show Gist options
  • Save shaunwallace/b8741ed93d13f41e6e70 to your computer and use it in GitHub Desktop.
Save shaunwallace/b8741ed93d13f41e6e70 to your computer and use it in GitHub Desktop.
Array.prototype.reduce()
// will return 15
[1,2,3,4,5].reduce(function(previousValue, currentValue){
return previousValue + currentValue;
});
// will return 25 since we passed in the initial value
[1,2,3,4,5].reduce(function(previousValue, currentValue){
return previousValue + currentValue;
}, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment