Skip to content

Instantly share code, notes, and snippets.

@alx8437
Last active May 16, 2020 20:17
Show Gist options
  • Save alx8437/2f564a1de5d6a3257f5580db253da60e to your computer and use it in GitHub Desktop.
Save alx8437/2f564a1de5d6a3257f5580db253da60e to your computer and use it in GitHub Desktop.
Array.prototype.diff = function(a) {
return this.filter(function(i) {return a.indexOf(i) < 0;});
};
////////////////////
// Examples
////////////////////
[1,2,3,4,5,6].diff( [3,4,5] );
// => [1, 2, 6]
["test1", "test2","test3","test4","test5","test6"].diff(["test1","test2","test3","test4"]);
// => ["test5", "test6"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment