feat: 09-caractere-mais-repetido

This commit is contained in:
Adilson Fernando Neves Ornellas 2022-10-29 00:51:09 -03:00
parent 522d6cf81e
commit 7ac176e0f0

View File

@ -1,4 +1,19 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
let palavra = text.toLowerCase().split('').sort().join('');
let totalLetras = 0;
let contandomais1 = 1;
let aLetra = "";
for (let i = 0; i < palavra.length; i++) {
if (palavra[i] === palavra[i + 1]) {
contandomais1++;
} else {
if (contandomais1 > totalLetras) {
totalLetras = contandomais1;
aLetra = palavra[i];
}
contandomais1 = 1;
}
}
return aLetra;
}