Skip to content

Instantly share code, notes, and snippets.

@francescoagati
Created August 30, 2010 10:03
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 francescoagati/557249 to your computer and use it in GitHub Desktop.
Save francescoagati/557249 to your computer and use it in GitHub Desktop.
a select_if for underscore.js
_.mixin({
select_if:function(data,options) {
if (options.cond()==true) {
return _(data).chain().filter(options.exec).value();
} else {
return data;
}
}
});
/*
example use:
_([1,2,3,4,5]).select_if({
cond:function() { return true },
exec:function(el) { return el > 4 }
})
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment