Build a Range of Numbers Generator - Test 5

Tell us what’s happening:

Hi everyone, I am sure i applied the recursion into my code and it outputs the correct arrays and passes all the tests, but the test still fails on 5. rangeOfNumbers should use recursion (call itself) to solve this challenge.

As to not reveal the full function code, I just changed my inner logic to js comment.

Your code so far

const rangeOfNumbers = (startNum, endNum) => {
  //initialise an array
  //if the starting number is greater than ending number, 
  //return the array.
  //Otherwise, assign the recursive function
  //back to the array and push the ending number
  //into the array then return it.
}

console.log(rangeOfNumbers(1, 5)); //T6
console.log(rangeOfNumbers(6, 9)); //T7
console.log(rangeOfNumbers(4, 4)); //T8
console.log(rangeOfNumbers(10, 15)); //T9
console.log(rangeOfNumbers(2, 8)); //T10

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36

Challenge Information:

Build a Range of Numbers Generator - Build a Range of Numbers Generator

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-range-of-numbers/5cc0bd7a49b71cb96132e54c.md at main · freeCodeCamp/freeCodeCamp · GitHub

we need to see your code to help

Hi, here’s my inner logic. Thanks.

  let numArr = [];

  if(startNum > endNum){
    return numArr;
  }
  else{
    numArr = rangeOfNumbers(startNum, endNum-1);
    numArr.push(endNum);
    return numArr;
  }

try using a named function not an arrow function

Thanks! That worked.
Is it best practice to handle recursion using normal function format instead of arrow function, or is this just a restriction set in the platform’s test runner?

no, it is a limitation of our tests

Good to know it’s just a test limitation. Thanks for clarifying!