Skip to content

Instantly share code, notes, and snippets.

@manuelgeek
Created March 9, 2023 09:25
Show Gist options
  • Save manuelgeek/fabebe4a1fe65206ba78587fbedd6da1 to your computer and use it in GitHub Desktop.
Save manuelgeek/fabebe4a1fe65206ba78587fbedd6da1 to your computer and use it in GitHub Desktop.
// Online Javascript Editor for free
// Write, Edit and Run your Javascript code using JS Online Compiler
// Write a fuction that adds numbers in array using recusrion. It should return 0 when array is empty.
// Do not use any of the loops
const list = [1,2,3]
function add(list){
if(!list.length) return 0
const sum = list[0] + add(list.slice(1))
return sum
}
console.log("Welcome to Programiz!", add(list));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment