Last active
March 3, 2020 20:55
-
-
Save mattbontrager/7500cc5696ff4efe249f2ac0adbeb8ec to your computer and use it in GitHub Desktop.
Find different elements between two arrays.
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.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