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:
commit
1326b7f9d5
@ -1,12 +1,21 @@
|
||||
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
export function mostUsedChar(text){
|
||||
const charMap = {};
|
||||
const stringToArray = text.split('')
|
||||
const obj = {}
|
||||
|
||||
for (const char of text.toLowerCase()) {
|
||||
/*5*/ charMap[char] = (charMap[char] || 0) + 1;
|
||||
}
|
||||
|
||||
return Object.values(charMap).filter((count) => count > 1).length;
|
||||
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]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user