Here’s the code
function rangeOfNumbers(startNum, endNum) {
return startNum === endNum
? [startNum]
: rangeOfNumbers(startNum, endNum - 1).concat(endNum);
}
I understand that until startNum
equals endNum
it will recall itself, but the thing that I don’t understand is where the value is stored?
Say for example it’s rangeOfNumbers(3,6)
So it’s gonna be like this:
6-1
5-1
4-1
Right? And each time the numbers are added to the array and we get [3,4,5,6]
, but I don’t understand how and where it stores this array.
If I’m not mistaken, concat
merges two or more arrays, but there are no arrays.
I just want to have a full understanding of it. Otherwise, I won’t remember it and won’t be able to use it.