feat(question): add tuple length (#17)

* feat(question): add tuple length

* Update questions/18-easy-tuple-length/info.yml

Accept suggestion

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>

* refactor(question): add tags tuple

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
This commit is contained in:
沧浪 2020-07-29 18:54:26 +08:00 committed by GitHub
parent 370295c959
commit 8ca8cc481b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 2 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,15 @@
<!--info-header-start--><h1>Tuple length <img src="https://img.shields.io/badge/-easy-90bb12" alt="easy"/> <img src="https://img.shields.io/badge/-%23tuple-999" alt="#tuple"/></h1><blockquote><p>by sinoon <a href="https://github.com/sinoon" target="_blank">@sinoon</a></p></blockquote><p><a href="https://type-challenges.netlify.app/18/play" target="_blank"><img src="https://img.shields.io/badge/-Take%20the%20Challenge-3178c6?logo=typescript" alt="Take the Challenge"/></a> </p><!--info-header-end-->
For given a tuple, you need create a generic `Length`, pick the length of the tuple
For example
```ts
type tesla = ['tesla', 'model 3', 'model X', 'model Y']
type spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT']
type teslaLength = Length<tesla> // expected 4
type spaceXLength = Length<spaceX> // expected 5
```
<!--info-footer-start--><br><a href="../../README.md" target="_blank"><img src="https://img.shields.io/badge/-Back-grey" alt="Back"/></a> <a href="https://type-challenges.netlify.app/18/solutions" target="_blank"><img src="https://img.shields.io/badge/-Check%20out%20Solutions-de5a77?logo=awesome-lists&logoColor=white" alt="Check out Solutions"/></a> <a href="https://type-challenges.netlify.app/18/answer" target="_blank"><img src="https://img.shields.io/badge/-Share%20your%20Solutions-green" alt="Share your Solutions"/></a> <!--info-footer-end-->

View File

@ -0,0 +1,8 @@
title: Length of Tuple
author:
name: sinoon
email: sinoon1218@gamil.com
github: sinoon
tags: tuple

View File

@ -0,0 +1 @@
title: 获取元组长度

View File

@ -0,0 +1 @@
type Length<T extends any> = any

View File

@ -0,0 +1,9 @@
import { Equal, Expect } from '@type-challenges/utils'
const tesla = ['tesla', 'model 3', 'model X', 'model Y']
const spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT']
type cases = [
Expect<Equal<Length<tesla>, 4>>,
Expect<Equal<Length<spaceX>, 5>>,
]