I have this code for a custom pop() method:
Array.prototype.pop = function(index) {
if (typeof index === "undefined") {
index = this.length - 1;
}
var rtn = this.slice()[index];
this.remove(this[index]);
return rtn;
};
It works perfectly when I input a paramater (e.g. [1,3,5].pop(1) returns 3 and removes it).
However, when I use it with no parameters (e.g. [1,3,5].pop()) it returns undefined and does not edit the array. I think it is to do with the fact that function overloading does not work with 0 parameters. Please can you help me find alternatives or a solution to this problem. Thanks.