Iterators Lab

Medium
1
60.0% Acceptance

In this lab, you will be creating a simple Counter iterator that counts from 0 to a given limit. You will be implementing this iterator using the Symbol.iterator method, which will allow using the iterator in for..of loops. Make sure to export the Counter iterator class from your index.js file using the ESM export default syntax.

To implement the iterator pattern, follow these steps:

  • Create a class Counter with a constructor accepting a limit value.
  • Implement the Symbol.iterator method in the class, returning an object with a next() function.
  • Inside the next() function, return an object with value and done properties.