Created
October 12, 2021 16:43
-
-
Save Dibasic/572be75e67473be5aac2befd2e201801 to your computer and use it in GitHub Desktop.
array prototype functions that i use
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
Array.prototype.unique = function() { return this.filter(function(val, idx) { return this.indexOf(val) === idx; }, this); }; | |
Array.prototype.union = function(that) { return this.concat(that).unique(); }; | |
Array.prototype.intersection = function(that) { return this.filter(function(val) { return that.indexOf(val) !== -1; }).unique(); }; | |
Array.prototype.difference = function(that) { return this.filter(function(val) { return that.indexOf(val) === -1; }).unique(); }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment