Skip to content

Instantly share code, notes, and snippets.

@kellywoo
Last active March 30, 2021 12:51
Show Gist options
  • Save kellywoo/d11522be816fd5c50b4dccbb78751442 to your computer and use it in GitHub Desktop.
Save kellywoo/d11522be816fd5c50b4dccbb78751442 to your computer and use it in GitHub Desktop.
1st homework
// [1,2,3,4,5,6]
const recursive = (arr, i) => arr.length === i ? 0 : (arr[i] + recursive(arr, i+1));
const recursiveWrapper = (arr) => recursive(arr, 0);
const recursiveTail = (arr, i, v)=> arr.length === i ? v : recursiveTail(arr, i+1, v+arr[i]);
const recursiveTailWrapper = (arr) => recursiveTail(arr, 0, 0);
const recursiveToFor = (arr) => {
let sum = 0;
for (let i = arr.length -1; i>=0; i--) {
sum+= arr[i]
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment