While working on the “Use Recursion To Create A Range Of Numbers” challenge I was Able to work out just about the entire solution on my own although I kept receiving the error “maximum call stack exceeded” So I thought that something was wrong with my base case and after tinkering for some time and finally giving up and looking at a solution I realized that the only thing I was missing was the “startNum” in this line:
const numArray = rangeOfNumbers(startNum, endNum - 1);
Originally I was calling the function with (endNum -1)
I’m just a bit confused on how exactly the absence of the startNum was causing the error “maximum stack call exceeded”.
Here is my solution with the addition of the startNum:
function rangeOfNumbers(startNum, endNum) {
if (endNum === startNum) {
return [startNum];
} else {
const numArray = rangeOfNumbers(startNum, endNum - 1);
numArray.push(endNum);
return numArray;
}
};