rimo030 / type-challenges

Collection of TypeScript type challenges with online judge
https://tsch.js.org/
MIT License
3 stars 0 forks source link

no - 9898 Appear only once #124

Open rimo030 opened 6 months ago

rimo030 commented 6 months ago
type RemoveAll<T extends any[], U> = T extends [U, ...infer R] 
  ? RemoveAll<R, U>
  : T

type FindEles<T extends any[], L extends any[] = []> = T extends [infer F, ...infer R]
  ? R extends [F, ...infer rest]
    ? FindEles<RemoveAll<rest, F>, L>
    : FindEles<R, [...L, F]>
  : L
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<FindEles<[1, 2, 2, 3, 3, 4, 5, 6, 6, 6]>, [1, 4, 5]>>,
  Expect<Equal<FindEles<[2, 2, 3, 3, 6, 6, 6]>, []>>,
  Expect<Equal<FindEles<[1, 2, 3]>, [1, 2, 3]>>,
]