2022-10-27 15:07:13 +00:00
|
|
|
export function mostUsedChar(text) {
|
2022-11-01 22:14:00 +00:00
|
|
|
// implementar logica aqui
|
|
|
|
const stringToArray = text.split('')
|
|
|
|
const obj = {}
|
|
|
|
|
|
|
|
stringToArray.forEach(element => {
|
|
|
|
obj[element] = obj[element] ? obj[element] + 1 : 1
|
|
|
|
})
|
|
|
|
|
|
|
|
const objToArray = Object.entries(obj)
|
|
|
|
|
|
|
|
let res = ['', 0]
|
|
|
|
|
|
|
|
objToArray.forEach(word => {
|
|
|
|
if (res[1] < word[1]) {
|
|
|
|
res = word
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return res[0]
|
|
|
|
}
|