feat: implementa função do caractere mais repetido

This commit is contained in:
RodrigoJorge 2022-10-28 16:00:31 -03:00
parent 94db3cf689
commit 96de2bd2c3

View File

@ -1,4 +1,16 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
}
const Objeto = {};
let Contador = 0;
let mostUsedChar = "";
for (let char of text) {
Objeto[char] = Objeto[char] + 1 || 1;
}
for (let key in Objeto) {
if (Objeto[key] > Contador) {
Contador = Objeto[key];
mostUsedChar = key;
}
}
return mostUsedChar;
}