Type Challenges Judge

LastIndexOf

提出詳細

type LastIndexOf<T extends unknown[], U> = T extends [...infer R, infer L] ? Equal<L, U> extends true ? R["length"] : LastIndexOf<R, U> : -1
提出日時2023-08-31 17:35:09
問題LastIndexOf
ユーザーookkoouu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<LastIndexOf<[1, 2, 3, 2, 1], 2>, 3>>, Expect<Equal<LastIndexOf<[2, 6, 3, 8, 4, 1, 7, 3, 9], 3>, 7>>, Expect<Equal<LastIndexOf<[0, 0, 0], 2>, -1>>, Expect<Equal<LastIndexOf<[string, 2, number, 'a', number, 1], number>, 4>>, Expect<Equal<LastIndexOf<[string, any, 1, number, 'a', any, 1], any>, 5>>, ]