Skip to content

Instantly share code, notes, and snippets.

@ArielLeslie
Created October 6, 2015 17:33
Show Gist options
  • Save ArielLeslie/e03e04580d48712442dd to your computer and use it in GitHub Desktop.
Save ArielLeslie/e03e04580d48712442dd to your computer and use it in GitHub Desktop.
Diff Two Arrays
function diff(arr1, arr2) {
//just add two two arrays together
var newArr = arr1.concat(arr2);
//then filter it
return newArr.filter(function(val){
// return true if the value is not in one of the arrays
if (arr1.indexOf(val) < 0 || arr2.indexOf(val) < 0){
return true;
}else{
return false;
}
});
}
diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment