forked from M3-Academy/challenge-algorithms-v2.0
15 lines
402 B
JavaScript
15 lines
402 B
JavaScript
export function mostUsedChar(text) {
|
|
// implementar logica aqui
|
|
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;
|
|
} |