Created
October 13, 2014 16:21
-
-
Save watson/8f5c36c5128b409a4a6c to your computer and use it in GitHub Desktop.
JavaScript Array filtering madness
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
// the data | |
var arr = ['foo', 'bar', 'baz']; | |
// the formal way | |
arr.filter(function (elm) { | |
return /a/.test(elm); | |
}); | |
// the one-liner | |
arr.filter(RegExp.prototype.test.bind(/a/)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment