Type Challenges Judge

Chunk

提出詳細

type Chunk<T extends unknown[], N extends number, A extends unknown[] = [], Res extends unknown[] = []> = T extends [infer E, ...infer R] ? [...A, E]["length"] extends N ? Chunk<R, N, [], [...Res, [...A, E]]> : Chunk<R, N, [...A, E], Res> : A["length"] extends 0 ? Res["length"] extends 0 ? [] : Res : [...Res, A]
提出日時2023-09-02 11:47:33
問題Chunk
ユーザーookkoouu
ステータス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]]>>, ]