Skip to content

Instantly share code, notes, and snippets.

@jomurgel
Last active July 8, 2018 21:34
Show Gist options
  • Save jomurgel/2de0159879b8c62a86e49c9bcbc654a2 to your computer and use it in GitHub Desktop.
Save jomurgel/2de0159879b8c62a86e49c9bcbc654a2 to your computer and use it in GitHub Desktop.
Remove Differences from 2 Arrays
const array1 = [1, 2, 3, 4, 5];
const array2 = [1];
// Return all but similariy.
array1.filter( item => array2.every( item2 => item2.id !== item.id ) ); // Returns [2, 3, 4, 5]
// Return similarity.
array1.filter( item => array2.every( item2 => item2.id === item.id ) ); // Returns [1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment