mostRepeatChar atualizado

This commit is contained in:
Nathalia Sardou 2022-10-31 17:50:50 -03:00
parent 0f1c198c1e
commit 9e1b18baef

View File

@ -1,4 +1,21 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
}
// implementar logica aqui
text = text.split('').sort();
let cont1 = 0;
let cont2 = 0;
let maior = '';
for (let i = 1; i < text.length; i++) {
if (text[i] != text[i - 1]) {
if (cont2 > cont1) {
cont1 = cont2;
maior = text[i - 1];
}
cont2 = 1;
} else {
cont2++;
}
}
return maior;
}