Tell us what’s happening:
Describe your issue in detail here.
i got the code working but still dont understand why it works. the following line especially
const myArray = rangeOfNumbers(startNum + 1, endNum);
why is endNum needed?
since the end condition is already set above with (startNum > endNum) why do we have to write (startNum + 1, endNum)? doesn’t the second argument define the length of the array?
newArray(valueToBeImplemented, nbOfTimesThisValuesGetsImplemented)
or newArray(1, 5); => newArray[1, 1, 1, 1, 1]
this line “myArray.unshift(startNum); " add the number at the begining of the array until the exit condition is reached " if (startNum > endNum)”
so why do i need to add endNum in const myArray = rangeOfNumbers(startNum + 1, endNum);
Your code so far
function rangeOfNumbers(startNum, endNum) {
if (startNum > endNum)
{
return [];
}else{
const myArray = rangeOfNumbers(startNum + 1, endNum);
myArray.unshift(startNum);
return myArray;
}
};
// rangeOfNumbers(1, 5) should return [1, 2, 3, 4, 5]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Challenge Information:
Basic JavaScript - Use Recursion to Create a Range of Numbers