Skip to content

Instantly share code, notes, and snippets.

@Dibasic
Created October 12, 2021 16:43
Show Gist options
  • Save Dibasic/572be75e67473be5aac2befd2e201801 to your computer and use it in GitHub Desktop.
Save Dibasic/572be75e67473be5aac2befd2e201801 to your computer and use it in GitHub Desktop.
array prototype functions that i use
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