I didn’t understand how this recursive function works, especially when I used the debugger, when it reached the base case so the if statement is correct and it should originally return the empty array and then stop, but suddenly it continued to the else statement even if “if” statement is correct, before reaching the base case n was decreasing and after reaching the base case it started to increase , also many times I thought that the function will stop it continued executing, actually I didn’t who how the code was returning from line 9 to 8 then 8 to 9 until n is in the max and even it was weird how is n increasing without increment statement help please
function countup(n) {
if (n < 1) {
return [];
} else {
const countArray = countup(n - 1);
countArray.push(n);
return countArray;
}
}
console.log(countup(5));