Created
August 31, 2016 15:57
-
-
Save jakeleboeuf/9cd820e52a32a7520bd0ceffe8cf1a5d to your computer and use it in GitHub Desktop.
Groking Algorithyms
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
// Recursive Sum fn() | |
let arr = [1,2,3]; | |
let sum = (_arr) => { | |
if (_arr.length === 1) { | |
return _arr[0]; | |
} else { | |
return _arr.shift() + sum(_arr); | |
} | |
}; | |
console.log(sum(arr)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment