Basic JavaScript - Use Recursion to Create a Range of Numbers

Tell us what’s happening:

Why in the world is my function not achieving the criteria? I does create an array of incrementing numbers and It looks almost the same as the actual solution. The only difference is that the solution function does it by decreasing the endNum and pushing it instead of incrementing the startNum and pushing it. It makes no sense!

Your code so far


function rangeOfNumbers(startNum, endNum) {
  if(startNum > endNum) return [];
   
   const myArray = rangeOfNumbers(startNum + 1, endNum);
   myArray.push(startNum);
   if(startNum == endNum) return myArray;

};



Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) 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

Where does push put the new element?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.