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

12 lines
368 B
JavaScript

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