If I wanted to write the pop function from scratch what would be the most efficient way? The main issue also is how do I return the originating array without the popped element?
Array.prototype.pop = function () {
var myArray = this;
var length = myArray.length;
var element = myArray[length-1];
myArray = myArray.slice(0,length-1);
return element;
}
var hello = [1,2,3,4,5];
hello.pop();
5
console.log(hello)
[1, 2, 3, 4, 5]