This is multiplication function that takes an array and n numbers of elements in the array and returns the multiplication of the N numbers of element in the array.
function multiply(arr, n) {
if (n <= 0)
return 1;
let first = multiply(arr, n - 1);
console.log(`first value: ${first}`);
console.log(typeof(first))
let second = arr[n - 1];
let result = first * second;
return result;
}
const mul = multiply([1,2,3],2);
console.log(mul)
How this recursion replace for or while loop?