Last active
November 30, 2016 04:56
-
-
Save KinoAR/c0f44a845060bca73ab74be2ac7624f1 to your computer and use it in GitHub Desktop.
Array.Reduce JavaScript Tutorial Code
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
'use strict'; | |
//Basic Reduce | |
let array = [1, 2, 3, 4, 5]; | |
let result = array.reduce(function(sum, element) { | |
//Increase sum by element amount | |
sum += element; | |
console.log(sum); //1, 3, 6, 10, 15 | |
return sum; //return the current sum for the next iteration | |
}, 0); | |
console.log(result); //15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment