feat: Soluciona o exercício 09 - Most repeated char

This commit is contained in:
Eleonora Otz de Mendonça Soares 2022-10-28 16:49:33 -03:00
parent 2d18f109e1
commit 32e2c086e3

View File

@ -1,4 +1,19 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
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
}