feat: criando o codigo do repeated caracterias

This commit is contained in:
PATRICK DE SOUZA SILVA 2022-11-01 19:14:00 -03:00
parent c6f6df9c59
commit e8427b22ee

View File

@ -1,4 +1,21 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
// 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]
}