-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (30 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Initializing the default set of censored words
var defaultCensoredWords = ["sad", "bad", "mad"];
// Using ES6 Set to allow efficient add and lookup operations
var customCensoredWords = new Set();
// Function to censor the input string
function censor(inputStr) {
// Replacing censored words from the default set
for (let word of defaultCensoredWords) {
inputStr = inputStr.replace(new RegExp(word, "gi"), "*****");
}
// Replacing censored words from the custom set
for (let word of customCensoredWords) {
inputStr = inputStr.replace(new RegExp(word, "gi"), "*****");
}
return inputStr;
}
// Function to add a word to the custom censored words set
function addCensoredWord(word) {
customCensoredWords.add(word);
}
// Function to get the combined list of censored words
function getCensoredWords() {
return [...defaultCensoredWords, ...customCensoredWords];
}
// Exporting the functions
module.exports = {
censor: censor,
addCensoredWord: addCensoredWord,
getCensoredWords: getCensoredWords
};