Type Challenges Judge

Sort

提出詳細

// 1:A<B, 0:A=B, -1:A>B type Comp<A extends number, B extends number> = A extends B ? 0 : "0123456789" extends `${string}${A}${string}${B}${string}` ? 1 : -1 type Merge<A extends number[], B extends number[], Desc extends boolean = false, _Res extends number[] = []> = A extends [infer A1 extends number, ...infer ARest extends number[]] ? B extends [infer B1 extends number, ...infer BRest extends number[]] ? Comp<A1, B1> extends -1 ? Desc extends true ? Merge<ARest, B, Desc, [..._Res, A1]> : Merge<A, BRest, Desc, [..._Res, B1]> : Desc extends true ? Merge<A, BRest, Desc, [..._Res, B1]> : Merge<ARest, B, Desc, [..._Res, A1]> : [..._Res, ...A] : [..._Res, ...B] type Sort<A extends number[], Desc extends boolean = false> = A extends [infer A1 extends number, infer A2 extends number, ...infer R extends number[]] ? Merge<Merge<[A1], [A2], Desc>, Sort<R, Desc>, Desc> : A
提出日時2024-09-14 08:47:37
問題Sort
ユーザーookkoouu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Sort<[]>, []>>, Expect<Equal<Sort<[1]>, [1]>>, Expect<Equal<Sort<[2, 1]>, [1, 2]>>, Expect<Equal<Sort<[0, 0, 0]>, [0, 0, 0]>>, Expect<Equal<Sort<[1, 2, 3]>, [1, 2, 3]>>, Expect<Equal<Sort<[3, 2, 1]>, [1, 2, 3]>>, Expect<Equal<Sort<[3, 2, 1, 2]>, [1, 2, 2, 3]>>, Expect<Equal<Sort<[3, 2, 0, 1, 0, 0, 0]>, [0, 0, 0, 0, 1, 2, 3]>>, Expect<Equal<Sort<[2, 4, 7, 6, 6, 6, 5, 8, 9]>, [2, 4, 5, 6, 6, 6, 7, 8, 9]>>, Expect<Equal<Sort<[1, 1, 2, 1, 1, 1, 1, 1, 1]>, [1, 1, 1, 1, 1, 1, 1, 1, 2]>>, Expect<Equal<Sort<[], true>, []>>, Expect<Equal<Sort<[1], true>, [1]>>, Expect<Equal<Sort<[2, 1], true>, [2, 1]>>, Expect<Equal<Sort<[0, 0, 0], true>, [0, 0, 0]>>, Expect<Equal<Sort<[1, 2, 3], true>, [3, 2, 1]>>, Expect<Equal<Sort<[3, 2, 1], true>, [3, 2, 1]>>, Expect<Equal<Sort<[3, 2, 1, 2], true>, [3, 2, 2, 1]>>, Expect<Equal<Sort<[3, 2, 0, 1, 0, 0, 0], true>, [3, 2, 1, 0, 0, 0, 0]>>, Expect<Equal<Sort<[2, 4, 7, 6, 6, 6, 5, 8, 9], true>, [9, 8, 7, 6, 6, 6, 5, 4, 2]>>, ]