Hi all,
I solved the copy machine problem in JS using a while loop, but afterwards I got curious about if I could have used recursion to do the same thing. Here’s what I wrote but it’s not working (error says Maximum call stack size exceeded):
function copyMachine(arr, num) {
let newArr = […arr];
if (num = 0){
return
} else {
return newArr.push(copyMachine(arr, num - 1))
}
}
console.log(copyMachine([true, false, true], 2));
Please advise!