Merge pull request 'feat: criando o codigo do repeated caracterias' (#7) from feature/repeated-char into develop

Reviewed-on: #7
This commit is contained in:
PATRICK DE SOUZA SILVA 2022-11-02 17:08:33 +00:00
commit 1326b7f9d5

View File

@ -1,12 +1,21 @@
export function mostUsedChar(text) {
// implementar logica aqui
const stringToArray = text.split('')
const obj = {}
// implementar logica aqui
export function mostUsedChar(text){
const charMap = {};
stringToArray.forEach(element => {
obj[element] = obj[element] ? obj[element] + 1 : 1
})
for (const char of text.toLowerCase()) {
/*5*/ charMap[char] = (charMap[char] || 0) + 1;
}
const objToArray = Object.entries(obj)
return Object.values(charMap).filter((count) => count > 1).length;
}
let res = ['', 0]
objToArray.forEach(word => {
if (res[1] < word[1]) {
res = word
}
})
return res[0]
}