Skip to content

Instantly share code, notes, and snippets.

@mkuklis
Created April 27, 2012 16:43
Show Gist options
  • Save mkuklis/2510679 to your computer and use it in GitHub Desktop.
Save mkuklis/2510679 to your computer and use it in GitHub Desktop.
underscore _.filterAll
(function (_, slice) {
_.filterAll = function (data) {
var filters = slice.call(arguments, 1);
return _.filter(data, function (item) {
var found = true;
for (var i = 0, l = filters.length; i < l; i++) {
found &= filters[i](item);
}
return found;
});
}
})(_, Array.prototype.slice);
var f1 = function (item) {
return item.a == 1;
}
var f2 = function (item) {
return item.b == 2;
}
var data = [{a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}, {a: 3, b: 2, c: 1}];
_.filterAll(data, f1, f2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment