removed set, replaces need to happen from longest word to shortest word

This commit is contained in:
Josh Guyette 2024-01-05 14:50:18 -06:00
parent 603ca61135
commit 2a877e05f0
1 changed files with 2 additions and 2 deletions

View File

@ -23,7 +23,7 @@ export interface FamilyFriendlyOptions {
// This class is used to detect or mask out, bad words in a string // This class is used to detect or mask out, bad words in a string
export class FamilyFriendly { export class FamilyFriendly {
// The list of bad words // The list of bad words
private badWords = new Set<string>(); private badWords: string[] = [];
constructor(options?: FamilyFriendlyOptions) { constructor(options?: FamilyFriendlyOptions) {
const allFalse = const allFalse =
@ -92,7 +92,7 @@ export class FamilyFriendly {
allWords.push(...badSpanishWords); allWords.push(...badSpanishWords);
} }
this.badWords = new Set(allWords); this.badWords = allWords.sort((a, b) => b.length - a.length);
} }
// Returns true if the string contains a bad word // Returns true if the string contains a bad word