forked from M3-Academy/challenge-algorithms-v2.0
feat: resolucao da funcao mostRepeatedChar
This commit is contained in:
parent
27c0c1f894
commit
d9cfdee306
@ -1,4 +1,23 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
return ""
|
||||
}
|
||||
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')
|
Loading…
Reference in New Issue
Block a user