-
-
Save remy/26201b7c00887bd4ff01 to your computer and use it in GitHub Desktop.
no swear
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 terms = ['shit', 'fuck'].map(s => ' ' + s + ' '); | |
var re = RegExp(terms.join('|')); | |
var hasBadWords = function (str) { return re.test(' ' + str + ' '); }; | |
hasBadWords("hit me duck"); // false | |
hasBadWords("holy shit"); // true | |
hasBadWords("My assistant couldn't find shitake mushrooms."); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't need the map.