Problem, as an interviewer would state it:
"Write a range(start, end, step) like lodash's — produces the sequence of numbers from start up to (not including) end, stepping by step. Then tell me a real reason to implement it as a generator instead of returning a plain array."
Examples:
[...range(0, 10, 2)] -> [0, 2, 4, 6, 8]
[...range(10, 0, -2)] -> [10, 8, 6, 4, 2]
Clarifying questions expected:
- Should this return a real array directly, or something lazily iterable (a generator)?
- Is a negative step expected to work symmetrically (counting down)?
- Should
endever be included, or always strictly exclusive like the real lodash behavior?
Code / implementation expected: Yes — real, direct proof that a generator-based range can represent a genuinely infinite sequence, which an array-materializing version structurally cannot.