Working on a font library, I store fonts like this:
var fonts = [
{
name: "Foo",
style: "Bar",
families: [
{ name: "A", parent: "B" },
{ name: "C", parent: "D" }
]
} // and so on...
];
And I want to filter out fonts whose families list contains { name: "A", parent: "B" }.
The filter looks like var selection = [{ name: "A", parent: "B" }]
Actually, the code look like this:
// Triggers when a new family is added to the filter
$scope.$on('filter:changed', function(e, selection) {
_.each($scope.fonts, function(font) {
_.each(font.families, function(family) {
_.each(selection, function(item) {
if(_.isMatch(family, item)) {
console.log('font', font);
console.log('has a match for family', family);
} else {
console.log('no match for family', family);
}
});
});
});
});
What is the best way to do it without performance impact, as there will be thousands font objects in the future?
findWhereorwherewhereto get the array orfindWhereif you want only one result$scope.fonts, then over the selectors (selectionarray) and test them with_.where, right?