Skip to content

Instantly share code, notes, and snippets.

@itsthatguy
Last active April 21, 2016 14:53
Show Gist options
  • Save itsthatguy/fd566be9f1cbef41d541c8ac8dae4624 to your computer and use it in GitHub Desktop.
Save itsthatguy/fd566be9f1cbef41d541c8ac8dae4624 to your computer and use it in GitHub Desktop.
let firstCollection = [
{id: 1, name: 'dog', item_id: 47},
{id: 2, name: 'truck', item_id: 38},
{id: 3, name: 'martian', item_id: 123}
];
let secondCollection = [
{id: 123, name: 'martian'}
];
let unusedItems = _.differenceWith(firstCollection, secondCollection, (firstItem, secondItem) => {
return firstItem.id === secondItem.item_id;
});
// => [{id: 1, name: 'dog', item_id: 47}, {id: 2, name: 'truck', item_id: 38}]
let unusedItems = _.reject(firstCollection, (firstItem) => {
let isDuplicate;
secondCollection.forEach((secondItem) => {
if (firstItem.id === secondItem.item_id) {
isDuplicate = true;
}
});
return isDuplicate;
});
// => [{id: 1, name: 'dog', item_id: 47}, {id: 2, name: 'truck', item_id: 38}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment