Skip to content

Instantly share code, notes, and snippets.

@RakshithNM
Last active June 21, 2017 17:56
Show Gist options
  • Save RakshithNM/25b4d49d11f4889f17474d3c9a055249 to your computer and use it in GitHub Desktop.
Save RakshithNM/25b4d49d11f4889f17474d3c9a055249 to your computer and use it in GitHub Desktop.
Finding the diff of two arrays
function diffArray(arr1, arr2) {
var newArr = [];
newArr = arr1.concat(arr2);
var filteredArray = newArr.filter(function(val) {
return (arr1.indexOf(val) < 0 || arr2.indexOf(val) < 0);
});
return filteredArray;
}
diffArray([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