Ed

Iterators let you define how objects are looped over with for...of. Understanding this unlocks powerful patterns like generators and lazy evaluation.

Your Task:

  • Create a Range class that represents a number range
  • Implement Symbol.iterator so it works with for...of
  • new Range(1, 5) should iterate: 1, 2, 3, 4, 5
  • Also implement toArray() method for convenience
TypeScript Solution
Loading...

Submit your code to see test results