Tell us what’s happening:
Describe your issue in detail here.
i cant seem to follow the code where the it calls the its own function countup(n-1). it seems to me it keep calling itself without every going to the next line with the push statement.
// Only change code below this line
function countdown(n){
if (n < 1) {
return [];
} else {
const countArray = countdown(n - 1);
countArray.switch(n);
return countArray;
}
// Only change code above this line
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36
so im missing something, it will keep calling its own function decrementing the value of n until the value is less than 1 and the function ends without ever seeing the line below the recursion. sorry im trying to make some sense out of this.
ok so i see it now . you keep calling the function til n=0 . and once it breaks out of the recursion and empy array is assigned to countArray and then the current value of n is pushed into the array, which is one. bujt now im confused how a 2,3 ,4 and 5 is generated. there is no increment before the return.
ok got it. so i take it the values for when n return a 4 3 2 1. dont go away . they are stored in some stack waiting to be used after the recursion is over and an array is returned. thanks alot for the help. sorry if i was being a bother earlier. oh and the switch was meant to be a unshift. i was trying to use the opposite of a push and put the eleme nt in the beginning of the array