Advertisement
nher1625

Censor_That_Shit

May 17th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var censoredWords = ["sad", "bad", "mad"];
  2. var customCensoredWords = [];
  3.  
  4. // Add string multiplication feature
  5. String.prototype.repeat = function( num ) {
  6.     return new Array( num + 1 ).join( this );
  7. }
  8. // Credit: (http://stackoverflow.com/questions/202605/repeat-string-javascript)
  9.  
  10. function censor(inStr) {
  11.     for (idx in censoredWords) {
  12.         inStr = inStr.replace(
  13.             censoredWords[idx], "*".repeat(censoredWords[idx].length)
  14.             );  // replace for word in censored words
  15.     }
  16.     for (idx in customCensoredWords) {
  17.         inStr = inStr.replace(
  18.             customCensoredWords[idx], "*".repeat(customCensoredWords[idx].length)
  19.             );  // ditto for custom array
  20.     }
  21.     return inStr;
  22. }
  23. function addCensoredWord(word) {
  24.     customCensoredWords.push[word];
  25. }
  26. function addCensoredWords(wordList) {
  27.     for (word in wordList) {
  28.         customCensoredWords.push(wordList[word]);
  29.     }
  30. }
  31. function getCensoredWords() {
  32.     return censoredWords.concat(customCensoredWords);  // Seems inefficient to have to have two separate arrays
  33. }
  34. exports.censor = censor;
  35. exports.addCensoredWord = addCensoredWord;
  36. exports.getCensoredWords = getCensoredWords;
  37. exports.addCensoredWords = addCensoredWords;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement