Created
March 17, 2016 20:08
-
-
Save henriquemenezes/80471af0b573de018675 to your computer and use it in GitHub Desktop.
JS array diff
This file contains hidden or 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
function arrayDiff(a1, a2) { | |
var diff = {}; | |
for (var i = 0; i < a1.length; i++) { | |
diff[a1[i]] = true; | |
} | |
for (var i = 0; i < a2.length; i++) { | |
if (diff[a2[i]]) { | |
delete diff[a2[i]]; | |
} else { | |
diff[a2[i]] = true; | |
} | |
} | |
return Object.keys(diff); | |
} | |
function isArrayDiff(a1, a2) { | |
return arrayDiff(a1, a2).length > 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment