Last active
June 25, 2019 22:39
-
-
Save vvatikiotis/de211a82d2fec03d381cfa6ad4aab8b1 to your computer and use it in GitHub Desktop.
This file contains 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
// 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