Skip to content

Instantly share code, notes, and snippets.

@mattbontrager
Last active March 3, 2020 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattbontrager/7500cc5696ff4efe249f2ac0adbeb8ec to your computer and use it in GitHub Desktop.
Save mattbontrager/7500cc5696ff4efe249f2ac0adbeb8ec to your computer and use it in GitHub Desktop.
Find different elements between two arrays.
Array.prototype.diff = function(arr2) {
let arr1 = this;
let diff = new Set();
arr1.forEach(item => !arr2.includes(item) && diff.add(item));
arr2.forEach(item => !arr1.includes(item) && diff.add(item));
return Array.from(diff);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment