Проверьте, не включены ли .every
запрещенных слов в комментарий, который вы просматриваете. Обязательно сначала наберите toLowerCase
в комментарии:
const comments = ["Very useful tutorial, thank you so much!", "React is not a damn framework, it's a LIBRARY",
"Why you put bloody kitten pictures in a tech tutorial is beyond me!", "Which one is better, React or Angular?", 'There is no "better", it depends on your use case, DAMN YOU'];
const bannedWords = ['bloody', 'damn'];
const result = comments.filter(comment => bannedWords.every(word => !comment.toLowerCase().includes(word)))
console.log(result);
Или, если вы хотите построить регулярное выражение:
const comments = ["Very useful tutorial, thank you so much!", "React is not a damn framework, it's a LIBRARY",
"Why you put bloody kitten pictures in a tech tutorial is beyond me!", "Which one is better, React or Angular?", 'There is no "better", it depends on your use case, DAMN YOU'];
const bannedWords = ['bloody', 'damn'];
const re = new RegExp(bannedWords.join('|'), 'i');
const result = comments.filter(comment => !re.test(comment));
console.log(result);