Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function rangeOfNumbers(startNum, endNum) {
if(startNum === endNum){
return [startNum];
} else{
if(startNum<endNum){
var x = rangeOfNumbers(startNum, endNum-1);
x.push(endNum)
console.log(x)
return x
}
}
return [];
};
**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.124 Safari/537.36
Challenge: Use Recursion to Create a Range of Numbers
Link to the challenge:
hello,
I did not understand this particular case : “x.push(endNum)” it should insert the elements at the end of the array, but in the recursion case when the endNum decrease if the push method do what it’s expected should return something like [5,4,3,2,1] and not [1,2,3,4,5]…so why basically happen?