Type Challenges Judge

Unique

提出詳細

type Contains<T extends readonly unknown[], U> = T extends [infer T1, ...infer T2] ? Equal<T1,U> extends true ? true : Contains<T2,U> : false type Unique<T extends readonly unknown[], Acc extends readonly unknown[] = []> = T extends [infer T1, ...infer T2] ? Contains<Acc,T1> extends true ? Unique<T2,Acc> : Unique<T2,[...Acc, T1]> : Acc
提出日時2023-09-18 08:02:48
問題Unique
ユーザーsankantsu
ステータス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]>>, ]