Skip to content

Commit

Permalink
fix(utils): excludeElements 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
ssi02014 committed Jul 5, 2024
1 parent fc6eb4d commit 03dbe70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/docs/utils/array/excludeElements.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

## Interface
```ts title="typescript"
const excludeElements: <T, U = T>(
const excludeElements: <T, U>(
array: T[] | readonly T[],
excludeArray: T[] | readonly T[],
iteratee?: (item: T) => U
iteratee?: ((item: T) => U) | undefined
) => T[];
```

Expand Down
17 changes: 11 additions & 6 deletions packages/utils/src/array/excludeElements/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { identity } from '../../common';

export const excludeElements = <T, U = T>(
export const excludeElements = <T, U>(
array: T[] | readonly T[],
excludeArray: T[] | readonly T[],
iteratee: (item: T) => U = identity as (item: T) => U
iteratee?: (item: T) => U
) => {
const excludeSet = new Set(excludeArray.map(iteratee));
const excludeArrayToUse = iteratee
? excludeArray.map(iteratee)
: excludeArray;

const exclusionSet = new Set<T | U>(excludeArrayToUse);

return array.filter((element) => !excludeSet.has(iteratee(element)));
if (iteratee) {
return array.filter((element) => !exclusionSet.has(iteratee(element)));
}
return array.filter((element) => !exclusionSet.has(element));
};

0 comments on commit 03dbe70

Please sign in to comment.