Last active
June 21, 2017 17:56
-
-
Save RakshithNM/25b4d49d11f4889f17474d3c9a055249 to your computer and use it in GitHub Desktop.
Finding the diff of two arrays
This file contains 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 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