challenge-algorithms-v2.0-m.../09-mostRepeatedChar/index.js

18 lines
413 B
JavaScript
Raw Normal View History

export function mostUsedChar(text) {
// implementar logica aqui
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
}