Use Recursion to Create a Countdown - Why not the reverse order?

I really don’t understand how come the .push() method is adding numbers in the array this way [ 1, 2, 3, 4, 5 ]. It looks like .unshift() to me.

.push() is supposed to simply add the numbers at the end. If so, in my understanding, the array should look like [5, 4, 3, 2, 1] because n = 5. I really can’t wrap my head around it. Someone please explain…

I appreciate anyone’s help big time. cheers.


The explanation on the challenge page shown below doesn’t really explain anything to me.

" At first, this seems counterintuitive since the value of n decreases , but the values in the final array are increasing . This happens because the push happens last, after the recursive call has returned."

Challenge: Use Recursion to Create a Countdown

Link to the challenge:

3 Likes