I've already looked into this for a couple of days and feel like I'm missing an obvious implementation here.
(see lodash Filter collection using array of values for something similar).
What I want to do is take a collection of items that a user already has, and then use that to filter from the entire list of items. There are number of ways to iterate through the list and create a new collection and return it, or a way to potentially create a mixin that does this, but I was curious if there's just a chain of one-liners or a concept I'm missing. The goal is to do a deep comparison of each object in the collection to determine equivalence.
Here's the example (jsFiddle here: http://jsfiddle.net/kxLt534f/)
var collection = [
{id:1, name:'one'},
{id:2, name:'two'},
{id:3, name:'three'}
];
var filter = [
{id:2, name:'two'}
];
// what I want to be able to do
// var result = _.someFilterMethod(collection,filter);
// what it looks liked I'll have to do
var filtered = _.select(collection, function(c){
var same = false;
_.forEach(filter,function(f) {
same = _.isEqual(f,c);
});
return !same;
});
console.warn(filtered); // output is : [{id:1,name:'one',id:3,name:'three'}]
There's gotta be a nicer way to do this, but I for the life of me can't see it. Any suggestions would be appreciated!