Iterators Lab
Medium
66.7% 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 alimit
value. - Implement the
Symbol.iterator
method in the class, returning an object with anext()
function. - Inside the
next()
function, return an object withvalue
anddone
properties.