Hi, take a look at my thread and the solution I have marked in
Hi could anyone explain to me the example function please?
I understand it is counting the number at first, but where does it store them?
so it started counting, 5,4,3,2,1
then it supposed to push ( countArray.push(n); ) why does it push it 5 times, I guess it should be stored somewhere.
**Your code so far**
function countup(n) {
if (n < 1) {
return [];
} else {
const countArray = countup(n - 1);
countArray.push(n);
return countArray;
}
}
console.log(countup(5));…
I had the same confusion, but the lessons to that point if I re call correctly don’t teach us about data structure yet, the solution answers that question fairly.
You can also use the help of this website : Online JavaScript Compiler, Visual Debugger, and AI Tutor - Learn JavaScript programming by visualizing code
it will show you how the function runs.
Cheers.
1 Like