feat(mostRepeatedChar): algoritmo concluido

This commit is contained in:
Mateus Antonio Rodrigues Lopes 2022-11-02 17:54:10 -03:00
parent d66c42f762
commit 6065ccf64c

View File

@ -1,4 +1,17 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
}
var textCounts = {}
var maxKey = ''
for (var i = 0; i < text.length; i++) {
var key = text[i]
if (!textCounts[key]) {
textCounts[key] = 0
}
textCounts[key]++
if (maxKey === '' || textCounts[key] > textCounts[maxKey]) {
maxKey = key
}
}
return maxKey
}