Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Created November 10, 2019 20:27
Show Gist options
  • Save luislobo14rap/9fba894f5726f78866e35b115858a892 to your computer and use it in GitHub Desktop.
Save luislobo14rap/9fba894f5726f78866e35b115858a892 to your computer and use it in GitHub Desktop.
array-alias.js
// array-alias.js v1
Array.prototype.add = function(){
return this.push(...arguments);
};
Array.prototype.add = Array.prototype.add; // alias
Array.prototype.addPrev = function(){
return this.unshift(...arguments);
};
Array.prototype.removeLast = function(quantity = 1){
console.log(quantity);
let this_ = this;
for(let i = 0; i < quantity; i++){
this_.pop();
};
return this_;
};
Array.prototype.removeFirst = function(quantity = 1){
console.log(quantity);
let this_ = this;
for(let i = 0; i < quantity; i++){
this_.shift();
};
return this_;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment