Skip to content

Instantly share code, notes, and snippets.

@ColinCampbell
Forked from gmoeck/gist:2596336
Created May 4, 2012 17:21
Show Gist options
  • Save ColinCampbell/2596345 to your computer and use it in GitHub Desktop.
Save ColinCampbell/2596345 to your computer and use it in GitHub Desktop.
var matchersForFilter = function(properties) {
var attributes = util.keys(properties);
var attributesFilters = util.values(properties);
var arrayOfMatchersForAttribute = util.map(
util.zip(attributes, attributesFilters), matchersForAttribute
);
var matchers = util.flatten(arrayOfMatchersForAttribute, true);
return matchers;
};
var matchersForAttribute = function(arrayWithAttributeAndFilters) {
var attribute = arrayWithAttributeAndFilters[0];
var filtersForAttribute = arrayWithAttributeAndFilters[1];
var types = util.keys(filtersForAttribute);
var values = util.values(filtersForAttribute);
var arraysWithTypeAndValue = util.zip(types, values);
var matchers = util.map(util.bind(matcherForTypeAndValue, this, attribute));
return matchers;
};
var matcherForTypeAndValue = function(attribute, arrayWithTypeAndValue) {
return {
type: arrayWithTypeAndValue[0],
attribute: attribute,
value: arrayWithTypeAndValue[1]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment