Skip to content

Instantly share code, notes, and snippets.

@holyjak
Last active November 20, 2015 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holyjak/10c11a436cd1cfd97541 to your computer and use it in GitHub Desktop.
Save holyjak/10c11a436cd1cfd97541 to your computer and use it in GitHub Desktop.
Simple or Complex? Familiar Imperative Code Or Makes-Me-Think Declarative One?
// Using http://lodash.com/ as `_`
// 1. IMPERATIVE
_(bundles).filter(function includeOnlyHandsets(bundle) {
if (!filter.hardwareType) return true;
return (bundle.product.type === filter.hardwareType);
})
// 2. DECLARATIVE
_(bundles).filter(filter.hardwareType ?
{bundle: {product: {type: filter.hardwareType}}} : null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment