I'm trying to replace a set of words in a text string. Now I have a loop, which does not perform well:
function clearProfanity(s) {
var profanity = ['ass', 'bottom', 'damn', 'shit'];
for (var i=0; i < profanity.length; i++) {
s = s.replace(profanity[i], "###!");
}
return s;
}
I want something that works faster, and something that will replace the bad word with a ###!
mark having the same length as the original word.
assassin
into******in
– Clarisaclarise