Tell us what’s happening:
If i’m reading the code right, wouldn’t it return [3, 7, 6, 5, 4,] ? Does javascript know to list them in order, or am I reading the code wrong? Just looking for help in understanding WHY the code works in sequential order.
Your code so far
function rangeOfNumbers(startNum, endNum) {
if (endNum === startNum) {
return [startNum];
} else {
var countArray = rangeOfNumbers (startNum, endNum - 1);
countArray.push (endNum);
return countArray;
}
};
console.log(rangeOfNumbers(3, 7));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
.
Challenge: Use Recursion to Create a Range of Numbers
Link to the challenge: