Skip to content

Instantly share code, notes, and snippets.

@MahmoudAgamy
Created February 13, 2019 15:44
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 MahmoudAgamy/342298a57df283a237754fbdcd8c6dbd to your computer and use it in GitHub Desktop.
Save MahmoudAgamy/342298a57df283a237754fbdcd8c6dbd to your computer and use it in GitHub Desktop.
// subtracting arr2 from arr1
let subtracting = arr1.filter(x => !arr2.includes(x));
// intersection between arr1 and arr2
let intersection = arr1.filter(x => arr2.includes(x));
// NotIntersection: all elements but intersection elements
let NotIntersection =
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