feat(mostRepeatedChar): Implementa função mostRepeatedChar #9

Merged
Daniel_Moliari_Barbosa merged 1 commits from feature/mostRepeatedChar into development 2022-10-28 18:15:53 +00:00

View File

@ -1,4 +1,16 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
const textObj = {}
let maxCount = 0
let mostUsedChar = ""
for (let char of text) {
textObj[char] = textObj[char] + 1 || 1
}
for (let key in textObj) {
if (textObj[key] > maxCount) {
maxCount = textObj[key]
mostUsedChar = key
}
}
return mostUsedChar
}