Invalid Array Length

In this challenge, you will build a function that creates an array for a given start, end, and step parameter.

  • The function takes three integer parameters: start, end, and step.
  • The function should return an array of numbers from start to end, counting by step.

The function checks for incorrect parameters by ensuring that;

  • start, end, or step are defined
  • start is not greater than end
  • step is greater than zero If any of these parameters are not met, the function should return an empty array [ ].

My code:

function range (start, end, step) {
  const result = [];
  for (let i = start; i <= end; i += step) {
    result.push(i);
  }
  return result;
}

RangeError: Invalid array length

Are you doing this part?