Back to Type Challenges

README

questions/03243-medium-flattendepth/README.md

latest1.6 KB
Original Source
<!--info-header-start--><h1>FlattenDepth </h1><blockquote><p>by jiangshan <a href="https://github.com/jiangshanmeta" target="_blank">@jiangshanmeta</a></p></blockquote><p><a href="https://tsch.js.org/3243/play" target="_blank"></a> </p><!--info-header-end-->

Recursively flatten array up to depth times.

For example:

typescript
type a = FlattenDepth<[1, 2, [3, 4], [[[5]]]], 2> // [1, 2, 3, 4, [5]]. flattern 2 times
type b = FlattenDepth<[1, 2, [3, 4], [[[5]]]]> // [1, 2, 3, 4, [[5]]]. Depth defaults to be 1

If the depth is provided, it's guaranteed to be positive integer.

<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/3243/answer" target="_blank"></a> <a href="https://tsch.js.org/3243/solutions" target="_blank"></a> <hr><h3>Related Challenges</h3><a href="https://github.com/type-challenges/type-challenges/blob/main/questions/00459-medium-flatten/README.md" target="_blank"></a> <!--info-footer-end-->