Can someone please help me with this question. I don’t think I understand the question at all.
I saw someone in another thread break down the question but it has since closed. they used the below formula as a way to explain. Could someone explain the `return arr[n - 1] * multiply(arr, n - 1) part to me? I dont understand why I have to multiply the array by itself?
var myArr = [1,2,3,4]
function multiply(arr, n) {
if (n <= 0) {
return 1;
} else {
return arr[n - 1] * multiply(arr, n - 1); // look at this
}
}
console.log(multiply(myArr, 4))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Replace Loops using Recursion
Link to the challenge: