-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Open
Description
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
🔢 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
Labels
No labels