Last active
July 8, 2018 21:34
-
-
Save jomurgel/2de0159879b8c62a86e49c9bcbc654a2 to your computer and use it in GitHub Desktop.
Remove Differences from 2 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
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