Created
January 15, 2017 15:45
-
-
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?
This file contains 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
//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