LastIndexOf
提出詳細
type LastIndexOf<T, U, Ans extends number=-1, Count extends readonly unknown[]=[]> = T extends [infer T1, ...infer T2] ? Equal<T1,U> extends true ? LastIndexOf<T2,U,Count["length"],[...Count,0]> : LastIndexOf<T2,U,Ans,[...Count, 0]> : Ans
提出日時 | 2023-09-18 07:55:17 |
---|---|
問題 | LastIndexOf |
ユーザー | sankantsu |
ステータス | 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>>, ]