Type Challenges Judge

Fill

提出詳細

type FillImplActive< T extends unknown[], N, End extends number, Pos extends readonly unknown[], > = End extends Pos["length"] ? T : T extends [infer T1, ... infer T2] ? [N, ...FillImplActive<T2,N,End,[...Pos,0]>] : [] type FillImplInactive< T extends unknown[], N, Start extends number, End extends number, Pos extends readonly unknown[], > = Start extends Pos["length"] ? FillImplActive<T,N,End,Pos> : T extends [infer T1, ...infer T2] ? [T1, ...FillImplInactive<T2,N,Start,End,[...Pos,0]>] : [] type Fill< T extends unknown[], N, Start extends number = 0, End extends number = T['length'], > = FillImplInactive<T,N,Start,End,[]>
提出日時2023-09-18 07:27:29
問題Fill
ユーザーsankantsu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Fill<[], 0>, []>>, Expect<Equal<Fill<[], 0, 0, 3>, []>>, Expect<Equal<Fill<[1, 2, 3], 0, 0, 0>, [1, 2, 3]>>, Expect<Equal<Fill<[1, 2, 3], 0, 2, 2>, [1, 2, 3]>>, Expect<Equal<Fill<[1, 2, 3], 0>, [0, 0, 0]>>, Expect<Equal<Fill<[1, 2, 3], true>, [true, true, true]>>, Expect<Equal<Fill<[1, 2, 3], true, 0, 1>, [true, 2, 3]>>, Expect<Equal<Fill<[1, 2, 3], true, 1, 3>, [1, true, true]>>, Expect<Equal<Fill<[1, 2, 3], true, 10, 0>, [1, 2, 3]>>, Expect<Equal<Fill<[1, 2, 3], true, 0, 10>, [true, true, true]>>, ]