sdfxs

Untitled

Jun 1st, 2021
1,063
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ArrayIterator<T> {
  2.     private elements: T[];
  3.     private index: number;
  4.     constructor(el: T[]) {
  5.         this.index = 0;
  6.         this.elements = el;
  7.     }
  8.  
  9.     next() {
  10.         return this.elements[this.index++];
  11.     }
  12.  
  13.     hasNext() {
  14.         return this.index < this.elements.length;
  15.     }
  16. };
  17.  
  18. const collection = new ArrayIterator<string>(['Один', 'Два', 'Три'])
  19.  
  20. while(collection.hasNext()) {
  21.     console.log(collection.next())
  22. }
RAW Paste Data