Created
October 15, 2015 04:32
-
-
Save platypusrex/80b309ef9fc58eacc792 to your computer and use it in GitHub Desktop.
Javascript - Compare two arrays and return a new array with any items not found in both of the original arrays.
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 diff(arr1, arr2) { | |
return newArr = arr1.filter(function(val){ | |
return arr2.indexOf(val) === -1; | |
}).concat(arr2.filter(function(val){ | |
return arr1.indexOf(val) === -1; | |
})); | |
} | |
diff(['diorite', 'andesite', 'grass', 'dirt', 'pink wool', 'dead shrub'], ['diorite', 'andesite', 'grass', 'dirt', 'dead shrub']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment