Unique
提出詳細
type Includes<T extends readonly unknown[], U> = T extends [infer F, ...infer R] ? Equal<F, U> extends true ? true : Includes<R, U> : false type Unique<T extends unknown[], U extends unknown[] = []> = T extends [infer F, ...infer R] ? Includes<U, F> extends true ? Unique<R, U> : Unique<R, [...U, F]> : U
提出日時 | 2023-08-31 17:29:28 |
---|---|
問題 | Unique |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Unique<[1, 1, 2, 2, 3, 3]>, [1, 2, 3]>>, Expect<Equal<Unique<[1, 2, 3, 4, 4, 5, 6, 7]>, [1, 2, 3, 4, 5, 6, 7]>>, Expect<Equal<Unique<[1, 'a', 2, 'b', 2, 'a']>, [1, 'a', 2, 'b']>>, Expect<Equal<Unique<[string, number, 1, 'a', 1, string, 2, 'b', 2, number]>, [string, number, 1, 'a', 2, 'b']>>, Expect<Equal<Unique<[unknown, unknown, any, any, never, never]>, [unknown, any, never]>>, ]