Skip to content

Instantly share code, notes, and snippets.

@watson
Created October 13, 2014 16:21
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 watson/8f5c36c5128b409a4a6c to your computer and use it in GitHub Desktop.
Save watson/8f5c36c5128b409a4a6c to your computer and use it in GitHub Desktop.
JavaScript Array filtering madness
// 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