feat(mostUsedChar): adicionando resolucao desafio 9

mostRepeatedChar
This commit is contained in:
Bernardo Cunha Ernani Waldhelm 2022-10-28 13:55:35 -03:00
parent 78aaef7f2f
commit 940dba1b38

View File

@ -1,4 +1,15 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
const value = text.toLocaleLowerCase().split("").sort();
let counts = {};
value.forEach(function (x) {
counts[x] = (counts[x] || 0) + 1;
});
const maior = Object.keys(counts).sort(function (a, b) {
return counts[a] > counts[b] ? -1 : counts[b] > counts[a] ? 1 : 0;
})[0];
return maior;
}