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

9 lines
354 B
JavaScript

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