Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var censoredWords = ["sad", "bad", "mad"];
- var customCensoredWords = [];
- // Add string multiplication feature
- String.prototype.repeat = function( num ) {
- return new Array( num + 1 ).join( this );
- }
- // Credit: (http://stackoverflow.com/questions/202605/repeat-string-javascript)
- function censor(inStr) {
- for (idx in censoredWords) {
- inStr = inStr.replace(
- censoredWords[idx], "*".repeat(censoredWords[idx].length)
- ); // replace for word in censored words
- }
- for (idx in customCensoredWords) {
- inStr = inStr.replace(
- customCensoredWords[idx], "*".repeat(customCensoredWords[idx].length)
- ); // ditto for custom array
- }
- return inStr;
- }
- function addCensoredWord(word) {
- customCensoredWords.push[word];
- }
- function addCensoredWords(wordList) {
- for (word in wordList) {
- customCensoredWords.push(wordList[word]);
- }
- }
- function getCensoredWords() {
- return censoredWords.concat(customCensoredWords); // Seems inefficient to have to have two separate arrays
- }
- exports.censor = censor;
- exports.addCensoredWord = addCensoredWord;
- exports.getCensoredWords = getCensoredWords;
- exports.addCensoredWords = addCensoredWords;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement