all files / util/ ArrayIterator.js

90.91% Statements 10/11
50% Branches 1/2
83.33% Functions 5/6
90.91% Lines 10/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                  1714× 1714×                     5225×                 3499× 3499× 3499×             21× 21×   21×       11×            
/*
  An iterator for arrays.
 
  @class
  @param {Array} arr
 */
class ArrayIterator {
 
  constructor(arr) {
    this.arr = arr
    this.pos = -1
  }
 
  get _isArrayIterator() {
    return true
  }
 
  /**
    @returns {Boolean} true if there is another child node left.
   */
  hasNext() {
    return this.pos < this.arr.length - 1
  }
 
  /**
    Increments the iterator providing the next child node.
 
    @returns {HTMLElement} The next child node.
   */
  next() {
    this.pos += 1
    var next = this.arr[this.pos]
    return next
  }
 
  /**
    Decrements the iterator.
   */
  back() {
    Eif (this.pos >= 0) {
      this.pos -= 1
    }
    return this
  }
 
  peek() {
    return this.arr[this.pos+1]
  }
 
}
 
export default ArrayIterator