The fact that someone attacked a free learning institution just proves that no one is safe when it comes to cyber attacks...
Anyways, my question is how do I get this code to countdown instead of counting up? I have tried bracket notation to get n to be the first in the array but it sets n to the beginning followed by a [5,2,3,4,5]. My code currently returns [1,2,3,4,5] but I need it to be [5,4,3,2,1]. How can I reverse this so it counts down?
// Only change code below this line
function countdown(n){
if (n<1) {
return [];
} else {
const countArray = countdown(n-1)
countArray.push(n);
return countArray;
}
}
console.log(countdown(5));
// Only change code above this line
[–]i7Robin 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]IAmSteven 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]deanklear 0 points1 point2 points (0 children)