Utils - Array
@teamsparta/utils에서 제공하는 배열 관련 유틸리티 함수입니다.
isEmptyArray
배열이 비어있는지 확인합니다.
API
typescript
function isEmptyArray<T>(array?: T[]): boolean;사용 예시
typescript
import { isEmptyArray } from '@teamsparta/utils';
isEmptyArray([]); // true
isEmptyArray([1, 2]); // false
isEmptyArray(undefined); // falseisLastIndex
주어진 인덱스가 배열의 마지막 인덱스인지 확인합니다.
API
typescript
function isLastIndex<T>(index: number, array?: T[]): boolean;사용 예시
typescript
import { isLastIndex } from '@teamsparta/utils';
isLastIndex(2, [1, 2, 3]); // true
isLastIndex(1, [1, 2, 3]); // falsegetLastItem
배열의 마지막 요소를 반환합니다. 배열이 아니거나 비어있으면 undefined를 반환합니다.
API
typescript
function getLastItem<T>(array?: T[]): T | undefined;사용 예시
typescript
import { getLastItem } from '@teamsparta/utils';
getLastItem([1, 2, 3]); // 3
getLastItem([]); // undefined
getLastItem(undefined); // undefinedunique
배열에서 중복을 제거한 새 배열을 반환합니다. Set을 사용합니다.
API
typescript
function unique<T>(array: readonly T[]): T[];사용 예시
typescript
import { unique } from '@teamsparta/utils';
unique([1, 2, 2, 3, 3]); // [1, 2, 3]
unique(['a', 'b', 'a']); // ['a', 'b']