how do you return a recursive function when there's promise inside it, here's my code so far
loop = (i) => {
new Promise((resolve) => {
setTimeout(() => {
resolve(i)
}, 100)
})
.then((res) => {
if (res <= 5) {
return loop(res + 1)
} else {
return true
}
})
}
console.log(loop(0))
return new Promise(...)? Otherwise each recursive call isn't part of the same chain.console.log()when you resolve the promise.returnkeyword for arrow functions that have a block body rather than just a one liner) but as a practical question, I'm not sure I understand why you'd ever use this. What's the real world use case?