Last active
May 18, 2019 10:56
-
-
Save homam/9c6aef175eb92546f79c34ffa28f3090 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
oneToTen.reduce(function(acc, a) { | |
return acc + a; | |
}, 0) |
This file contains hidden or 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
let sum = function(arr) { | |
let acc = 0 // the accumulated sum | |
for(var i = 0; i < arr.length; i++) { | |
let a = arr[i] // ith item in the array | |
acc += a | |
} | |
return acc | |
} | |
sum(oneToTen) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment