Back to Type Challenges

README

questions/00216-extreme-slice/README.md

latest1.4 KB
Original Source
<!--info-header-start--><h1>Slice </h1><blockquote><p>by Anthony Fu <a href="https://github.com/antfu" target="_blank">@antfu</a></p></blockquote><p><a href="https://tsch.js.org/216/play" target="_blank"></a> </p><!--info-header-end-->

Implement the JavaScript Array.slice function in the type system. Slice<Arr, Start, End> takes the three argument. The output should be a subarray of Arr from index Start to End. Indexes with negative numbers should be counted from reversely.

For example

ts
type Arr = [1, 2, 3, 4, 5]
type Result = Slice<Arr, 2, 4> // expected to be [3, 4]
<!--info-footer-start-->

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