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

21 lines
415 B
JavaScript
Raw Normal View History

export function mostUsedChar(text) {
2022-11-02 15:58:37 +00:00
let freqCounter = [];
let textStr = text.toLowerCase();
for (let char of textStr) {
freqCounter[char] = freqCounter[char] + 1 || 1;
}
let maxCount = 0;
let maxChar = null;
for (let key in freqCounter) {
if (freqCounter[key] > maxCount) {
maxCount = freqCounter[key];
maxChar = key;
}
}
// implementar logica aqui
return maxChar;
}