Tell us what’s happening:
Hi! This is the first time im participating in the forum so im sorry if my code explanation doesn’t read that well.
I think i ve been getting stuck around the return part of a function. What’s happening here? Why does “return result.unshift(startNum);” not add any numbers to the array inside the variable i’ve created?
Your code so far
[spoiler]
function rangeOfNumbers(startNum, endNum) {
//Set a base case
if (startNum = endNum) {
var result = [];
//startNum has been increased to the same value as endNum so i push it to be the last element of my array
result.push(startNum);
return result;
} else {
//increase my startNum for the next function
rangeOfNumbers(startNum +1, endNum);
//unshift startNum
return result.unshift(startNum);
}
};
[/spoiler]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
.
Challenge: Use Recursion to Create a Range of Numbers
Link to the challenge: