What is different for my program?

Tell us what’s happening:
i dont’t know what i am doing wrong. I’ve created an array, pushed the increasing number in the array and finally returned it with them.

  **Your code so far**


function rangeOfNumbers(startNum, endNum) {
if(startNum===endNum){
  return [endNum];
}
else{
  let a =[]
  a.push(rangeofNumber(startNum+1,endNum));
  return a;

}
};


//
//create arr
//if start===end, print [end]
//if start!=end
//array.push(start)
//foo(start+1)
//return arr
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:

Why are you redefining an empty array every time you call this function?

This function always returns an array. The key idea of recursion is to call the function with a reduced input and use the output of that function call.

1 Like

you are right! i did’nt notice it before. and here i am who spent 2 days on something which could’ve been solved in two minutes.

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