You need Login/Signup to run/submit the code.
How to implement Array.prototype.unshift? JavaScript Interview Question | Problem Solving | JavaScript Polyfills
@Yomesh Gupta
In this question, the candidate needs to implement a function customUnshift
that mimics the behaviour of Array.prototype.unshift
method.
More about Array.prototype.unshift
The unshift()
method adds one or more elements to the beginning of an array and returns the new length of the array.
Examples
const array = [1, 2, 3];
array.unshift(4, 5);
// prints [4,5,1,2,3]
console.print(array);
Syntax
unshift(element0)
unshift(element0, element1)
unshift(element0, element1, /* … ,*/ elementN)
Parameters
elementN
The elements to add to the front of the arr.
Return value
The new length
property of the object upon which the method was called.
Submission
Start the timer, complete your solution, and test it against the testcases provided by the platform. Ideally, you should finish this question within 30 mins. Share your solution with us -- https://twitter.com/devtoolstech