Skip to content

Instantly share code, notes, and snippets.

@bflannery
Created January 15, 2017 15:45
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 bflannery/0e4c7de81cd6d7f2da59f0c2de856381 to your computer and use it in GitHub Desktop.
Save bflannery/0e4c7de81cd6d7f2da59f0c2de856381 to your computer and use it in GitHub Desktop.
Given an array of X integers, can you find the sum of its elements?
//Given an array of X integers, can you find the sum of its elements?
function sumArr(arr) {
let sum = arr.reduce((a,b) => {
return a+b;
}, 0);
return sum;
}
console.log(sumArr([1,2,3,4,10,11]));
console.log(sumArr([2,6,9,15,25,42]));
console.log(sumArr([19,42,98,15,10,3]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment