Created
June 6, 2013 19:12
-
-
Save SegFaultAX/5724089 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yep. I see how this would be a bit better.