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

23 lines
478 B
JavaScript

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