forked from M3-Academy/challenge-algorithms-v2.0
<Feture>(09-mostRepeatedChar): implementação do código MostReapeat
This commit is contained in:
parent
008f01d480
commit
985af27572
@ -1,4 +1,9 @@
|
|||||||
export function mostUsedChar(text) {
|
export function mostUsedChar(text) {
|
||||||
// implementar logica aqui
|
// implementar logica aqui
|
||||||
return ""
|
let words = {}
|
||||||
|
const texts = text.toLowerCase().split("").sort();
|
||||||
|
texts.forEach((word) => words[word] = (words[word] || 0) + 1);
|
||||||
|
const maxVal = Math.max(...Object.values(words));
|
||||||
|
const word = Object.keys(words).find((key) => words[key] === maxVal);
|
||||||
|
return word
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user