Chunk
提出詳細
type Chunk< T extends readonly unknown[], N extends number, C extends readonly unknown[]=[]> = T extends [] ? C extends [] ? [] : [C] : C["length"] extends N ? [C, ...Chunk<T,N>] : T extends [infer T1, ...infer T2] ? Chunk<T2,N,[...C, T1]> : never
提出日時 | 2023-09-18 07:08:45 |
---|---|
問題 | Chunk |
ユーザー | sankantsu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Chunk<[], 1>, []>>, Expect<Equal<Chunk<[1, 2, 3], 1>, [[1], [2], [3]]>>, Expect<Equal<Chunk<[1, 2, 3], 2>, [[1, 2], [3]]>>, Expect<Equal<Chunk<[1, 2, 3, 4], 2>, [[1, 2], [3, 4]]>>, Expect<Equal<Chunk<[1, 2, 3, 4], 5>, [[1, 2, 3, 4]]>>, Expect<Equal<Chunk<[1, true, 2, false], 2>, [[1, true], [2, false]]>>, ]