Skip to content

Commit

Permalink
fix(test): lazy mode not working and improved performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Sep 13, 2023
1 parent fc7a672 commit ee14827
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions frontend/src/ts/test/lazy-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,20 @@ export function replaceAccents(
): string {
if (!word) return word;

const accentMap = new Map(accentsOverride || accents);

const accentsArray = accentsOverride || accents;
const uppercased = word.toUpperCase();
const cases = Array(word.length);

for (let i = 0; i < word.length; i++) {
cases[i] = word[i] === uppercased[i] ? 1 : 0;
}

const newWordArray: string[] = [];

for (let i = 0; i < word.length; i++) {
const char = word[i];
if (accentMap.has(char)) {
newWordArray.push(accentMap.get(char) as string);
const uppercasedChar = uppercased[i];
cases[i] = char === uppercasedChar ? 1 : 0;
const accent = accentsArray.find((accent) =>
accent[0].includes(char.toLowerCase())
);
if (accent) {
newWordArray.push(accent[1]);
} else {
newWordArray.push(char);
}
Expand Down

0 comments on commit ee14827

Please sign in to comment.