Would this function use tail recursion?
function doStuff(param) {
if (someExitCondition) {
return [];
}
// maybe manipulate param somehow
return [...doStuff(param - 1), value]; // spread the recursive function's result and append 1 item.
}
If not, is it possible to refactor it such that it can use tail recursion?
I suspect the fact that the result of the recursive function has an unknown size prevents tail recursion from being possible here, but I'm not certain on that.
N.B. In my case the maximum iterations is likely to be low and thus the impact of tail recursion would be negligable or possibly even 0? Thus I would class this as a premature microptimisation.
So this is mostly an academic question for which I am curious about the answer.