Last active
June 15, 2018 17:58
-
-
Save eday69/818fb88f92038fc01dd13177f6f619ea to your computer and use it in GitHub Desktop.
freeCodeCamp Intermediate Algorithm Scripting: Diff 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
// Compare two arrays and return a new array with any items only found | |
// in one of the two given arrays, but not both. In other words, return | |
// the symmetric difference of the two arrays. | |
function diffArray(arr1, arr2) { | |
return arr1.concat(arr2).filter( | |
info => !arr1.includes(info) || !arr2.includes(info)); | |
} | |
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