Skip to content

Commit

Permalink
revert: contains revert
Browse files Browse the repository at this point in the history
  • Loading branch information
ssi02014 committed Sep 27, 2024
1 parent bf0050e commit 3b121cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
5 changes: 0 additions & 5 deletions .changeset/good-books-carry.md

This file was deleted.

15 changes: 8 additions & 7 deletions packages/utils/src/array/contains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* 기본적으로 `Object.is`를 사용하여 비교를 수행하며, 사용자 정의 비교 함수(comparator)를 사용할 수 있습니다.
*
* @template T - 배열의 요소 타입입니다.
* @template U - 검색할 값의 타입으로, 배열 요소 타입(T)와 같거나 하위 타입이어야 합니다.
* @param {T[] | readonly T[]} arr - 검색할 배열입니다. 변경 불가능한 읽기 전용 배열도 허용됩니다.
* @param {U} value - 배열에서 찾고자 하는 값입니다.
* @param {(x: T, y: U) => boolean} [comparator=Object.is] - 배열의 요소와 찾고자 하는 값을 비교할 때 사용할 사용자 정의 비교 함수입니다. 기본값은 `Object.is`입니다.
Expand All @@ -12,20 +11,22 @@
* @example
* // 기본 비교 함수 사용 (Object.is)
* const numbers = [1, 2, 3];
*
* contains(numbers, 2); // true
* contains(numbers, 4); // false
*
* @example
* // 사용자 정의 비교 함수 사용
* const objects = [{ id: 1 }, { id: 2 }];
* const comparator = (a: { id: number }, b: { id: number }) => a.id === b.id;
* contains(objects, { id: 2 }, comparator); // true
* contains(objects, { id: 3 }, comparator); // false
*
* contains(objects, { id: 2 }, (a, b) => a.id === b.id); // true
* contains(objects, { id: 3 }, (a, b) => a.id === b.id); // false
*/
export function contains<T, U extends T>(
export function contains<T>(
arr: T[] | readonly T[],
value: U,
comparator: (x: T, y: U) => boolean = Object.is
): value is U {
value: unknown,
comparator: (x: any, y: any) => boolean = Object.is
): value is T {
return arr.some((item) => comparator(item, value));
}

0 comments on commit 3b121cb

Please sign in to comment.