feat: resolucao da funcao mostRepeatedChar

This commit is contained in:
Guilherme de Camargo Barbosa 2022-10-29 19:47:09 -03:00
parent 27c0c1f894
commit d9cfdee306

View File

@ -1,4 +1,23 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
let arr = []
for (let i = 0; i < text.length; i++) {
arr.push(text[i])
}
let counts = {}
arr.forEach(count => {
counts[count] = (counts[count] || 0) + 1
})
const maxValue = Math.max(...Object.values(counts))
const mostUsed = Object.keys(counts).find((key) => {
return counts[key] === maxValue
})
return mostUsed
}
mostUsedChar('banana')