0
Hours
0
Minutes
0
Seconds
You need Login/Signup to run/submit the code.

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

@Devtools Tech
321

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...