这是indexloc提供的服务,不要输入任何密码
Skip to content

16 - Pop (🎥 Video Explanation and Solution) #21550

@dimitropoulos

Description

@dimitropoulos

16 - Pop

Pop is another in the series of challenges that focus on reimplementing common array prototype methods. It's very straightforward and arguably belongs in the "easy" difficulty set. Still, we had fun solving it!

🎥 Video Explanation

Release Date: 2023-01-22 19:00 UTC

Pop

🔢 Code

// ============= Test Cases =============
import type { Equal, Expect } from './test-utils'

type A1 = Pop<[3, 2, 1]>;
type B1 = [3, 2];
type C1 = Expect<Equal<A1, B1>>;

type A2 = Pop<['a', 'b', 'c', 'd']>;
type B2 = ['a', 'b', 'c'];
type C2 = Expect<Equal<A2, B2>>;

type A3 = Pop<[]>;
type B3 = [];
type C3 = Expect<Equal<A3, B3>>;

// ============= Your Code Here =============
type Pop<T extends unknown[]> =
  // also: `infer _`
  T extends [...infer Head, unknown]
  ? Head
  : []
;

➕ More Solutions

For more video solutions to other challenges: see the umbrella list! #21338

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions