Tell us what’s happening:
How do I solve this challange, I have no idea on how to…
Your code so far
//Only change code below this line
function countdown(myArray, n){
if((n <= 0)){
return [];
} else {
countdown(myArray, n - 1);
myArray.splice(myArray.length - (n - 1), 0, n);
return myArray;
}
}
console.log(countdown([1, 5])); // [5, 4, 3, 2, 1]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
.
Challenge: Use Recursion to Create a Countdown
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-countdown