0
Hours
0
Minutes
0
Seconds

How to implement Array.prototype.shift? JavaScript Interview Question | Problem Solving | JavaScript Polyfills
@Devtools Tech

264

In this question, the candidate needs to implement a function customShift that mimics the behaviour of Array.prototype.shift method.

More about Array.prototype.shift

The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.

Examples

const array = [1, 2, 3];
const firstElement = array.shift();

// prints 1
console.print(firstElement);

// prints [2,3]
console.print(array);

Syntax

shift()

Return value

The removed element from the array; undefined if the array is empty.

Submission

Start the timer, complete your solution, and test it against the test cases provided by the platform. Ideally, you should finish this question within 30 mins. Share your solution with us -- https://twitter.com/devtoolstech

Loading IDE...