function rangeOfNumbers(startNum, endNum) {
if (endNum <= startNum) {
return [startNum];
} else {
var arr = rangeOfNumbers(startNum, endNum - 1);
arr.push(endNum);
}
return arr;
};
I’m still new to how recursion works but I finally decided to check the solution and noticed it was only because I was missing [startNum];
.
I thought once the loop reached 0 or the startNum I would just need to enter return;
to end the loop.
I checked on the debugger. Why does the expression return [startNum];
return an array for the else statement? I noticed without the brackets the var arr does not have an array.