#16Medium

Pop

Remove the last element from an array. Learn array type operations in this medium-level challenge on TypeScriptPro.

In this medium-level challenge, you'll implement a generic Pop<T> that removes the last element from an array.

Challenge Instructions: Pop

Medium

Implement a generic Pop<T> that takes an Array T and returns an Array without it's last element.

For example

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]

Extra*: Similarly, can you implement Shift, Push and Unshift as well?

Change the following code to make the test cases pass (no type check errors).

Loading...

Video Walkthrough

Detailed Explanation

type Pop<T extends unknown[]> = T extends [...infer Keep, infer Last] ? Keep : T

How it works:

This challenge is originally from here.

Share this challenge

Join early, learn faster.

Be the first to access the course, unlock exclusive launch bonuses, and get special early-bird pricing before anyone else.

No spam, unsubscribe at any time. We respect your privacy.

Limited Availability

Only 27 Spots left

Early Access

Get 1 month early access

>75% Off

Pre-Launch discount