16 - Pop (alt: Shift, Push, Unshift)

作者: ganda1fero创建于 2026年9月8日更新于 2026年9月8日
标签answeren16
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<[]>, []>>,
  Expect<Equal<Shift<[3, 2, 1]>, [2, 1]>>,
  Expect<Equal<Shift<['a', 'b', 'c', 'd']>, ['b', 'c', 'd']>>,
  Expect<Equal<Shift<[]>, []>>,
  Expect<Equal<Push<[3, 2, 1], 0>, [3, 2, 1, 0]>>,
  Expect<Equal<Push<['a', 'b', 'c', 'd'], 'e'>, ['a', 'b', 'c', 'd', 'e']>>,
  Expect<Equal<Push<[], 1>, [1]>>,
  Expect<Equal<Unshift<[3, 2, 1], 4>, [4, 3, 2, 1]>>,
  Expect<Equal<Unshift<['a', 'b', 'c', 'd'], 'hi'>, ['hi', 'a', 'b', 'c', 'd']>>,
  Expect<Equal<Unshift<[], 1>, [1]>>,
];

内容来源: type-challenges/type-challenges