feat: Soluciona o exercício 09 - Most repeated char
This commit is contained in:
parent
2d18f109e1
commit
32e2c086e3
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user