Skip to content

Instantly share code, notes, and snippets.

@eday69
Last active June 15, 2018 17:58
Show Gist options
  • Save eday69/818fb88f92038fc01dd13177f6f619ea to your computer and use it in GitHub Desktop.
Save eday69/818fb88f92038fc01dd13177f6f619ea to your computer and use it in GitHub Desktop.
freeCodeCamp Intermediate Algorithm Scripting: Diff Two Arrays
// 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