Skip to content

Instantly share code, notes, and snippets.

@platypusrex
Created October 15, 2015 04:32
Show Gist options
  • Save platypusrex/80b309ef9fc58eacc792 to your computer and use it in GitHub Desktop.
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.
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