Back to Type Challenges

README

questions/05153-medium-indexof/README.md

latest1.3 KB
Original Source
<!--info-header-start--><h1>IndexOf </h1><blockquote><p>by Pineapple <a href="https://github.com/Pineapple0919" target="_blank">@Pineapple0919</a></p></blockquote><p><a href="https://tsch.js.org/5153/play" target="_blank"></a> </p><!--info-header-end-->

Implement the type version of Array.indexOf, indexOf<T, U> takes an Array T, any U and returns the index of the first U in Array T.

ts
type Res = IndexOf<[1, 2, 3], 2>; // expected to be 1
type Res1 = IndexOf<[2,6, 3,8,4,1,7, 3,9], 3>; // expected to be 2
type Res2 = IndexOf<[0, 0, 0], 2>; // expected to be -1
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/5153/answer" target="_blank"></a> <a href="https://tsch.js.org/5153/solutions" target="_blank"></a> <!--info-footer-end-->