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

19 lines
463 B
JavaScript

export function mostUsedChar(text) {
// implementar logica aqui
let freqCounter = {}
let lcText = text.toLowerCase()
for (let char of lcText) {
freqCounter[char] = freqCounter[char] + 1 || 1;
}
let maxCount = 0;
let mostUsedChar = null;
for(let key in freqCounter) {
if(freqCounter[key] > maxCount) {
maxCount = freqCounter[key]
mostUsedChar = key
}
}
return mostUsedChar
}