Skip to content

Instantly share code, notes, and snippets.

@jakeleboeuf
Created August 31, 2016 15:57
Show Gist options
  • Save jakeleboeuf/9cd820e52a32a7520bd0ceffe8cf1a5d to your computer and use it in GitHub Desktop.
Save jakeleboeuf/9cd820e52a32a7520bd0ceffe8cf1a5d to your computer and use it in GitHub Desktop.
Groking Algorithyms
// 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