Problem, as an interviewer would state it:
"Implement a Range class that can be used in for...of, spread and destructuring, by implementing the iterator protocol by hand. No generator functions."
Examples:
[...new Range(0, 10, 3)]; // [0, 3, 6, 9]
for (const x of new Range(5, 0, -2)) {} // 5, 3, 1
Clarifying questions expected:
- Is the end exclusive, and are negative steps supported?
- Should a range be iterable more than once, and should it support an infinite end?
- What should happen for a step of zero, and what about fractional steps?
Code / implementation expected: Yes — real, direct proof the object works with every consumer of the iterable protocol, including early exit.