All files / src/iterators WhereIterator.js

100% Statements 7/7
100% Branches 4/4
100% Functions 2/2
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22        135x   135x 4x     131x       95x 350x 131x          
import Iterator from './Iterator';
 
export default class SkipIterator extends Iterator {
  constructor(arr, condition) {
    super(arr);
 
    if (typeof condition !== 'function') {
      throw new Error('Condition must be a function');
    }
 
    this.condition = condition;
  }
 
  *[Symbol.iterator]() {
    for (let item of this.arr) {
      if (this.condition(item)) {
        yield item;
      }
    }
  }
}