Build a Range with a Step
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write range(start, end, step), where step defaults to 1: return an array of numbers from start up to but not including end, going up by step each time. A negative step counts down instead, from start towards end, again stopping before it reaches end. When start equals end, or step points away from end, return an empty array. A step of 0 throws a RangeError. All the numbers in the checks are whole numbers.
Your code must pass
- Counts up from start to just before end
- Goes up by step
- Counts down with a negative step
- Returns an empty array when step points away from end
- Throws a RangeError for a step of 0