Skip to content

Commit

Permalink
fix(skipWhile): fix and add tests for skipWhile
Browse files Browse the repository at this point in the history
  • Loading branch information
biggyspender committed Jun 14, 2019
1 parent 17c9345 commit 5925e45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/extensions/skipWhile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ function skipWhile<T>(this: Enumerable<T>, pred: IndexedPredicate<T>): Enumerabl
const src = this
return EnumerableGenerators.fromGenerator(function*() {
let i = 0
let skip = true
for (const item of src) {
const result = pred(item, i++)
if (result) {
continue
if (skip) {
const result = pred(item, i++)
if (result) {
continue
}
}
skip = false
yield item
}
})
Expand Down
3 changes: 3 additions & 0 deletions test/blinq.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ describe('blinq test', () => {
it('skip', () => {
expect([...blinq([1, 2, 3]).skip(1)]).toEqual([2, 3])
})
it('skipWhile', () => {
expect([...blinq([1, 2, 3, 4, 1, 5]).skipWhile(x => x < 3)]).toEqual([3, 4, 1, 5])
})
it('take', () => {
expect([...blinq([1, 2, 3]).take(2)]).toEqual([1, 2])
})
Expand Down

0 comments on commit 5925e45

Please sign in to comment.