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 | 26x 26x 2x 24x 1x 23x 18x 18x 86x 53x 33x | import Iterator from './Iterator'; export default class SkipIterator extends Iterator { constructor(arr, count) { super(arr); if (isNaN(count)) { throw new Error('Missing count.'); } if (count < 0) { throw new Error('Count cannot be negative.'); } this.count = count; } *[Symbol.iterator]() { let index = this.count; for (let item of this.arr) { if (index-- > 0) { continue; } else { yield item; } } } } |