Make a Range You Can Loop Over
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write range(start, end), for whole numbers start and end: return an iterable object, not an array, that gives the numbers from start up to but not including end, counting up by 1. Give the object a Symbol.iterator method, so it works in a for...of loop, with spread syntax and with Array.from: [...range(1, 4)] gives [1, 2, 3]. The same range can be looped over as many times as you like, even in a loop nested inside another loop over it, and gives the same numbers every time. When end isn't above start, it gives nothing.
Your code must pass
- Works with for...of and spread
- Is an iterable object, not an array
- Can be looped over again, even inside itself
- Is empty when end isn't above start