Replace Loops(can't understand how recursion works

@veronika2001
For example

let someArr = [5, 9, 7, 2, 3, 4];
console.log(someArr[0]); // 5
console.log(someArr[1]); // 9
console.log(someArr[2]); // 7
console.log(someArr[3]); // 2
console.log(someArr[4]); // 3
console.log(someArr[5]); // 4

If you run sum(someArr, 5) , this is how it works:
(PS the function is actually multiplying not summing, so you should probably either change the function to summing or change the function name to something indicating multiplying)

1 Like