Skip to content

Instantly share code, notes, and snippets.

@homam
Last active May 18, 2019 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save homam/9c6aef175eb92546f79c34ffa28f3090 to your computer and use it in GitHub Desktop.
Save homam/9c6aef175eb92546f79c34ffa28f3090 to your computer and use it in GitHub Desktop.
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