Hello, In this exercise I have to write a function called countDown where it takes in an argument of type integer (n) and will print out n - 1 in descending order, so if 4 was passed in as (n) when I run code I should get 4, 3, 2, 1. So far in my code I have been able to simply print out these numbers however Im having an issue understanding how to push these numbers into a new array which is apart of what the original question wants me to do.
function countDown(n) {
if (n < 1) {
return [];
} else {
console.log(n);
const countDecrease = countDown(n - 1);
countDecrease.push(n);
return countDecrease;
}
}
countDown(4);
**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.114 Safari/537.36
Challenge: Use Recursion to Create a Countdown
Link to the challenge: