Tell us what’s happening:
Describe your issue in detail here.
I dont understand this line of code mean: let num = rangeOfNumbers(startNum, endNum - 1);
What is num value now? is it a function? for example endNum is 3 and startNum is 0 now num is rangeOfNumbers(0, 2);?
if yes what does that mean? a variable that become a function i am confuse about that.
**Your code so far**
function rangeOfNumbers(startNum, endNum)
{
if (endNum - startNum === 0)
{
return [startNum];
}
else
{
let num = rangeOfNumbers(startNum, endNum - 1);
num.push(endNum);
return num;
}
};
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36
Challenge: Use Recursion to Create a Range of Numbers
Because as it works through that function, it first gets to rangeOfNumbers and has to stop at that line to evaluate that recursive call, so it starts a function call, then it gets to the line with rangeOfNumbers, has to evaluate that recursive call, so it starts a function call, then it gets to the line with rangeOfNumbers… it keeps doing that until it has a function call that can finish, when endNum - startNum === 0, then it can finally finish a function call and it returns an array, after that, they incomplete function calls cascade finish, returning the array each time, so that push line will always have an array.
I think a big part of understanding recursion is understanding how the call stack works, even in just a qualitative sense. Put in a bunch of log statements and see in what order different lines get called. Or search the forum - there are A LOT of threads discussing this, some with detailed explanations.