Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created June 30, 2020 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/7273ccdbc4d6aad35d2a2576e501eb3d to your computer and use it in GitHub Desktop.
Save BetterProgramming/7273ccdbc4d6aad35d2a2576e501eb3d to your computer and use it in GitHub Desktop.
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