← All Exercises
Iterator Protocol Implementation
intermediatetypescript
Background
The iterator protocol enables custom objects to work with for-of loops, spread syntax, and destructuring.
Problem
Create a Range class that implements the iterable protocol, allowing it to be used with for-of loops and spread syntax.
Input
A start number, an end number, and an optional step.
Output
An iterable that yields numbers from start to end.
Sample tests
Sample 1
Input: new Range(1, 5)
Expected: [1, 2, 3, 4, 5]
Your solution
Learning objective
Understand the iterable protocol, Symbol.iterator, and generator functions.