challenge-algorithms-v2.0-a.../09-mostRepeatedChar/index.js

14 lines
362 B
JavaScript
Raw Permalink Normal View History

export function mostUsedChar(text) {
// implementar logica aqui
let counts = {};
Array.from(text).forEach((count) => {
counts[count] = (counts[count] || 0) + 1;
});
const maxVal = Math.max(...Object.values(counts));
const num = Object.keys(counts).find((key) => {
return counts[key] === maxVal;
});
return num;
}