Tell us what’s happening:
I’m pretty sure the problem is with the base case, but I can’t figure out what it is. It says Maximum call stack size exceeded, but shouldn’t it have stopped running once endNum is the same as startNum.
code so far**
function rangeOfNumbers(startNum, endNum) {
if (endNum === startNum) {
return [];
} else {
var arr = rangeOfNumbers(endNum - 1);
arr.push(endNum);
return arr;
}
}
console.log(rangeOfNumbers(1, 5))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36
.
Challenge: Use Recursion to Create a Range of Numbers
Link to the challenge: