feat(mostRepeatedChar): Implementa função mostRepeatedChar

This commit is contained in:
danielmoliaribarbosa 2022-10-28 15:15:21 -03:00
parent 2cf01bdc9f
commit 77abbade21

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
}