Created
August 30, 2010 10:03
-
-
Save francescoagati/557249 to your computer and use it in GitHub Desktop.
a select_if for underscore.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_.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