Skip to content

Instantly share code, notes, and snippets.

@homam
Last active May 18, 2019 10:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
oneToTen.reduce(function(acc, a) {
return acc + a;
}, 0)
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