Tell us what’s happening:
i don’t quiet understand
const countArray = countup(n - 1); => 5, 4 , 3, 2, 1 ""minus 1 with every loop""
countArray.push(n); => the .push() will add the value of "n" at the end of array.
so the logical final result should [ 5, 4, 3, 2, 1] but the example shows the reverse
in the same way
const countArray = countup(n - 1); => 5, 4 , 3, 2, 1 ""minus 1 with every loop""
countArray.unshift(n); => the .unshift() will add the value of "n" at the beginning of
the array
so the logical final result should [ 1, 2, 3, 4, 5]
and also is this syntax correct .push(n - 1)
Your code so far
// Only change code below this line
function countdown(n){
if (n < 1) {
return [];
} else {
const down = countdown(n - 1);
down.unshift(n);
return down;
}
}
// Only change code above this line
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
.
Challenge: Use Recursion to Create a Countdown
Link to the challenge: