Skip to content

Instantly share code, notes, and snippets.

@gmoeck
Created May 4, 2012 17:20
Show Gist options
  • Save gmoeck/2596336 to your computer and use it in GitHub Desktop.
Save gmoeck/2596336 to your computer and use it in GitHub Desktop.
var matchersForFilter = function(properties) {
var attributes = util.keys(properties);
var attributesFilters = util.values(properties);
var arraysWithAttributeAndAttributesFilters = util.zip(attributes,
attributesFilters);
var arrayOfMatchersForAttribute =
util.map(arraysWithAttributeAndAttributesFilters, 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