Tell us what’s happening:
I am trying to understand the process/ logic of this exercise.
it asks that if (n<1) it should return an empty array,
if (n===5) then the array shoud return [5,4,3,2,1] &
if (n===10) then the array shoud return [10,9,8…1]
just not sure enough how to put it into code.
any help much appreciated.
thank you
Your code so far
// Only change code below this line
function countdown(n){
if (n < 1){
return[];
}else {
if(n===10){
return[n-1];
}
const countArray = countdown(n-1);
countArray.push(n);
return countArray;
}
}
// Only change code above this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0.
The code you have now is implementing a counting up, not counting down, which is why the tests are not passing.
You have to inform the function to begin at the number it was given and then count down from there. This can be done in a few ways: using concat or the spread operator are two. Here is one example:
Im struggling to get my head arround the logic, you say I am using a countup, how is this?
Thats why I am not understanding how the logic quite works yet.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
The intent in this exercise is for you to take the countup example code and modify it to instead countdown. Countup uses push, but you can change that to a countdown by changing the push to a [???].
Recursion is an especially tricky idea that requires synthesis of many previous ideas. Breaking the problem down into smaller pieces is a key technique that I use professionally every day.
Const means something like constant
They are a bit like var but cannot be reasigned
we learn about them in ES6
the countArray is just the name of the array
Many thanks.
Oh No!!!
the next challenge is even more complicated!!
I think it has something to do with(min,max)
I will have to break it down into pieces.