You need Login/Signup to run/submit the code.
How to implement Array.prototype.push? JavaScript Interview Question | Problem Solving | JavaScript Polyfills
@Yomesh Gupta
In this question, the candidate needs to implement a function customPush
that mimics the behaviour of Array.prototype.push
method.
More about Array.prototype.push
The push()
method adds one or more elements to the end of an array and returns the new length of the array.
Examples
const array = [1, 2, 3];
array.push(4, 5);
// prints [1,2,3,4,5]
console.print(array);
Syntax
push(element0)
push(element0, element1)
push(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