Basic JavaScript - Use Recursion to Create a Range of Numbers

Hello everyone , i have a question

First this is the code

function rangeOfNumbers(startNum, endNum) {
  if (endNum < startNum) {
    return [];
  } else {
    const countArray = rangeOfNumbers(startNum, endNum - 1);
    countArray.push(endNum);
    return countArray;
  }

Why (endNum - 1) what does it mean? I def know endNum, yet why subtracting 1 from endNum??
**Challenge:** Basic JavaScript - Use Recursion to Create a Range of Numbers

**Link to the challenge:**
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers

Hello!

I found something that may answer your question for you.

I hope it helps.

1 Like

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