I've created a working recursive for loop, but it only works if my callback has no arguments. I've tried callback(arguments)
and callback(...arguments)
.
Thanks for any help you can provide!
function loopFunc (numOfSteps, callback) {
let i = 0;
if (i >= numOfSteps) {
let i = 0
return
}
callback()
loopFunc(numOfSteps - 1, callback)`enter code here`
}
It works if the callback takes no arguments:
function noArgsHello() {
console.log('hello')
}
const thisWorks = loopFunc(3, noArgsHello);
thisWorks()
It doesn't work if the callback takes an argument:
function sayHello (input) {
console.log(input)
}
const thisDoesntWork = loopFunc(3, sayHello('hello');
thisDoesntWork()