I have this filter, which I don't like:
var products = this.store.filter('product', function(product) {
var ok = true;
if (compatibility) {
ok = ok && product.compatibility == compatibility;
}
if (format) {
ok = ok && product.format == format;
}
if (priceRange) {
ok = ok && product.priceRange == priceRange;
}
if (productType) {
ok = ok && product.productType == productType;
}
return ok;
});
Basically, the filter function must return true for products which pass the test, and false for those which don't pass the test. The filter parameters can have a value of be null .
What is the more idiomatic way of rewriting the filter function?
return falseon negative cases which'd make the function just 5 lines long. However, I'd pass the code review as is.if (compatibility && product.compatibility != compatibility) return;'product'doing infilter('product', …)?function(product) ...part)