Skip to content

Instantly share code, notes, and snippets.

@SegFaultAX
Created June 6, 2013 19:12
Show Gist options
  • Save SegFaultAX/5724089 to your computer and use it in GitHub Desktop.
Save SegFaultAX/5724089 to your computer and use it in GitHub Desktop.
var exists = function(x) { return x != null; };
var truthy = function(x) {
return (x !== false) && exists(x);
};
var _filter = function(fun) {
return function(coll) {
var results = [];
if (coll == null) return results;
coll.forEach(function(value, index, list) {
if (truthy(fun.call(null, value))) results.push(value);
});
return results;
};
};
function filter(fun) {
var coll = arguments[1];
var f1 = _filter(fun);
if (exists(coll)) return f1(coll);
else return f1;
}
@fogus
Copy link

fogus commented Jun 6, 2013

Yep. I see how this would be a bit better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment