Created
November 10, 2019 20:27
-
-
Save luislobo14rap/9fba894f5726f78866e35b115858a892 to your computer and use it in GitHub Desktop.
array-alias.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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