Skip to content

Commit

Permalink
fix: uniq functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Apr 21, 2018
1 parent 4aabc05 commit 4268083
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ export namespace sortBy {
}

export function uniq<T>(arr: T[]): T[] {
return arr.filter((a, i) => {
return !arr.find((b, j) => j !== i && b === a)
})
return arr.filter((a, i) => arr.indexOf(a) === i)
}

export function uniqWith<T>(arr: T[], fn: (a: T, b: T) => boolean): T[] {
return arr.filter((a, i) => {
return !arr.find((b, j) => j !== i && fn(a, b))
return !arr.find((b, j) => j > i && fn(a, b))
})
}

0 comments on commit 4268083

Please sign in to comment.