00016-medium-pop
Medium
array

チャレンジのソース: type-challenges/00016-medium-pop

この課題ではTypeScript 4.0が推奨されます

配列 T を受け取り、最後の要素を除いた配列を返す汎用的な Pop<T> を実装してください。

例えば

type arr1 = ['a', 'b', 'c', 'd']
type arr2 = [3, 2, 1]

type re1 = Pop<arr1> // expected to be ['a', 'b', 'c']
type re2 = Pop<arr2> // expected to be [3, 2]

おまけ: 同様に ShiftPushUnshift も実装できますか?

Loading...
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<Pop<[3, 2, 1]>, [3, 2]>>,
  Expect<Equal<Pop<['a', 'b', 'c', 'd']>, ['a', 'b', 'c']>>,
  Expect<Equal<Pop<[]>, []>>,
]