Skip to content

Instantly share code, notes, and snippets.

@Woodsphreaker
Created March 13, 2018 19:19
Show Gist options
  • Save Woodsphreaker/d89e0c46f12d1a642194d9ac47d91fc5 to your computer and use it in GitHub Desktop.
Save Woodsphreaker/d89e0c46f12d1a642194d9ac47d91fc5 to your computer and use it in GitHub Desktop.
Compare between elements
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