forked from M3-Academy/challenge-algorithms-v2.0
feat: 09-caractere-mais-repetido
This commit is contained in:
parent
522d6cf81e
commit
7ac176e0f0
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user