TypeScript·

15 - Last of Array

  • #Type Challenges
  • #TypeScript

질문

이 챌린지에는 TypeScript 4.0 사용이 권장됩니다.

배열 T를 사용하고 마지막 요소를 반환하는 제네릭 Last<T>를 구현합니다.

예시

1
type arr1 = ['a', 'b', 'c']
2
type arr2 = [3, 2, 1]
3
4
type tail1 = Last<arr1> // expected to be 'c'
5
type tail2 = Last<arr2> // expected to be 1
6
7

풀이