Skip to content

Instantly share code, notes, and snippets.

@vvatikiotis
Last active June 25, 2019 22:39
Show Gist options
  • Save vvatikiotis/de211a82d2fec03d381cfa6ad4aab8b1 to your computer and use it in GitHub Desktop.
Save vvatikiotis/de211a82d2fec03d381cfa6ad4aab8b1 to your computer and use it in GitHub Desktop.
// Monkey patch Array.prototype
Object.assign(Array.prototype, {
unique() {
return this.filter((value, index, array) => {
return array.indexOf(value) === index;
});
}
});
// Object facade to Array object
var obj = {
length: 0, //only length is required to mimic an Array
add: function(elem){
Array.prototype.push.call(this, elem);
},
filter: function(callback) {
return Array.prototype.filter.call(this, callback); //or provide your own implemetation
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment