Created
March 9, 2023 09:25
-
-
Save manuelgeek/fabebe4a1fe65206ba78587fbedd6da1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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