Make a Class Iterable with Symbol.iterator
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write a class Range(start, end, step = 1) that implements Iterable<number>: looping over it gives start, start + step and so on, stopping before end (counting down when step is negative, and giving nothing when start is already past end). It must work with for...of and spread, any number of times. Type it so the loop variable and spread array are numbers, and non-numeric bounds are rejected.
Your code must pass
- Counts up to end, not including it
- Counts with a step, up or down
- Can be looped over more than once
- Has no type errors
- for...of gives numbers
- Spreads into a number array
- Rejects bounds that aren't numbers