Spot the bug - #145: Chat Filter Validator

Why is my pirate word filter censoring clean words?

function filterPirateChat(message) {
  const bannedWords = ["scurvy", "booty", "plank"];
  // build regex from banned list
  const pattern = new RegExp(bannedWords.join("|"), "i");
  return pattern.test(message);
}

console.log(filterPirateChat("an explanation is required")); // returns true!

Reply with what is broken and how you would fix it.

Lol this is a classic regex problem. “an explanation” has “plank” inside it. you need to use word boundaries with \b so it’s \b(scurvy|booty|plank)\b