Did i put range in rong why

Tell us what’s happening:

Your code so far


function rangeOfNumbers(startNum, endNum) {
return [startNum,endNum];
};

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 9; SM-A105F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Mobile Safari/537.36.

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:

You’re missing the key recursion logic in your code. You have to first test to make sure you’re not getting the same start and end number, and then call the function recursively to print the output.

function rangeOfNumbers(startNum, endNum) {
  return startNum === endNum // check for equality
    ?  [startNum] // equal, so just return the first number

    // not equal, so return the function passed with the
    // parameter options given
    :  [...rangeOfNumbers(startNum, endNum - 1), endNum ];
}
1 Like

Tell us what’s happening:

Your code so far


function rangeOfNumbers(startNum, endNum) {
return startNum==endNum
?[startnum]
:rangeOfNumbers(startNum-emdNum-1).concat(endNum);
}

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 9; SM-A105F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Mobile Safari/537.36.

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:

In the recursive case you must call rangeOfNumbers with two arguments. You are calling it with one. Why is the .concat method there?

1 Like