Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ArrayIterator<T> {
- private elements: T[];
- private index: number;
- constructor(el: T[]) {
- this.index = 0;
- this.elements = el;
- }
- next() {
- return this.elements[this.index++];
- }
- hasNext() {
- return this.index < this.elements.length;
- }
- };
- const collection = new ArrayIterator<string>(['Один', 'Два', 'Три'])
- while(collection.hasNext()) {
- console.log(collection.next())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement