I have managed to pass this, but i have a question as to why this method in the code below doesnt work. If anything i should get an array or why do i get the undefined.
Recursion works by making the problem smaller and smaller until you get to the smallest version of the problem. But that small version needs a solution so that you can build the recursive case up from that result.
like this works, but as soon as i take the first if statement somehow it just doesnt work anymore. ```javascript if (startNum === endNum) {
return [startNum];
}else if (startNum <= endNum) {
const counterArr = rangeOfNumbers(startNum, endNum - 1);
counterArr.push(endNum);
return counterArr;
}
};
Note: Recursive functions must have a base case when they return without calling the function again (in this example, when n <= 0 ), otherwise they can never finish executing.
Thanks a lot Jeremy, i see were the problem is and now hopefully it will stick.
The logic is incomplete without a base case. Recursion is saying that floor 5 of a skyrise is built on top of floor 4 and floor 4 is built on top of 3… The base case says how the first floor is built.