Skip to content

Instantly share code, notes, and snippets.

@robpataki
Created May 11, 2017 16:23
Show Gist options
  • Save robpataki/0eaf3a4e1e74c1d2b0c67270d73ee495 to your computer and use it in GitHub Desktop.
Save robpataki/0eaf3a4e1e74c1d2b0c67270d73ee495 to your computer and use it in GitHub Desktop.
Add up numbers in an array
function addUp(arr) {
return arr.reduce(function(a, b){return a+b;}, 0)
}
var arr = [1, 2, 3, 4, 5];
var sum = addUp(arr); //15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment