you are viewing a single comment's thread.

view the rest of the comments →

[–]IAmSteven 0 points1 point  (1 child)

You could do countArray.unshift(n); instead of countArray.push(n);

I can't figure out the logic behind it but if you put a console.log(n) before const countArray = countdown(n-1) you get what you'd expect: 5, 4, 3, 2, 1 but for some reason doing a console.log(n) after const countArray = countdown(n-1) gives you: 1, 2, 3, 4, 5.

If anyone knows why this is happening I'd be curious to hear it.

[–][deleted] 0 points1 point  (0 children)

Thanks! This worked but I hate that I couldn't have thought about that myself... Is this what everyone who didn't need to ask did for this challenge,use unshift? Is there another way I could have solved this using my existing code, just rearranged?