Skip to content

Commit

Permalink
Merge pull request #253 from andersonleite/refactor-utils-uniq
Browse files Browse the repository at this point in the history
Refactor 'uniq' function to use a Set.
  • Loading branch information
jeffijoe committed Aug 16, 2021
2 parents 0577359 + 19b5e06 commit 05af932
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,6 @@ export function isFunction(val: any) {
* @return {Array<T>}
* The deduped array.
*/
export function uniq<T>(arr: Array<T>): Array<T> {
const result: Array<T> = []
for (const idx in arr) {
const item = arr[idx]
if (result.indexOf(item) === -1) {
result.push(item)
}
}

return result
export function uniq<T>(arr: Array<T>): Array<T> {
return Array.from(new Set(arr))
}

0 comments on commit 05af932

Please sign in to comment.