Created
March 13, 2018 19:19
-
-
Save Woodsphreaker/d89e0c46f12d1a642194d9ac47d91fc5 to your computer and use it in GitHub Desktop.
Compare between elements
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 arr1 = [{id: 5, msg: 'hshh'}, {id: 56, msg: 'hshgdh'}, {id: 7, msg: 'hshh'}] | |
const arr2 = [{id: 5, msg: 'hshh'}, {id: 6, msg: 'hshgdh'}, {id: 7, msg: 'hshh'}] | |
const compare = (list1, list2) => { | |
const map = new Map() | |
for (let {id, msg} of list1) { | |
map.set(id, msg) | |
} | |
return list2.filter(({id, msg}) => !map.has(id)) | |
} | |
compare(arr1, arr2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment