Last active
April 26, 2019 09:48
-
-
Save kostandy/d4e3f559e15999b3a760092ef7240d00 to your computer and use it in GitHub Desktop.
Recursive sum of array of numbers
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
const sum = arr => { | |
return arr.length ? arr[arr.length - 1] + sum(arr.splice(1)) : 0; | |
} | |
const arr = [1, 2, 3, 4, 5, 6, 7]; | |
sum(arr); // 49 | |
export default sum; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment