Last active
April 21, 2016 14:53
-
-
Save itsthatguy/fd566be9f1cbef41d541c8ac8dae4624 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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'} | |
]; |
This file contains hidden or 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
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}] |
This file contains hidden or 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
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