Skip to content

Instantly share code, notes, and snippets.

@derekedelaney
Created July 23, 2018 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derekedelaney/52fd438c133e3b3005a2b3dbbce65163 to your computer and use it in GitHub Desktop.
Save derekedelaney/52fd438c133e3b3005a2b3dbbce65163 to your computer and use it in GitHub Desktop.
simple javascript helper functions
// Intersection
let intersection = arr1.filter(x => arr2.includes(x));
// Difference
let difference = arr1.filter(x => !arr2.includes(x));
// Symmetric Difference
let difference = arr1
.filter(x => !arr2.includes(x))
.concat(arr2.filter(x => !arr1.includes(x)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment