Created
June 30, 2020 14:50
-
-
Save BetterProgramming/7273ccdbc4d6aad35d2a2576e501eb3d to your computer and use it in GitHub Desktop.
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
function addingUpTo(arr, idx) { | |
// initiate sum at arr[idx] | |
let sum = arr[idx] | |
// base case: idx === 0 | |
if (idx === 0) { | |
return sum | |
} | |
// adding backward | |
return sum + addingUpTo(arr, idx - 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment