forked from M3-Academy/challenge-algorithms-v2.0
feat(mostRepeatedChar): Adiciona a logica do algoritmo que retorna a letra mais repetida de uma string
This commit is contained in:
parent
89b3ba787a
commit
83b587aa86
@ -1,4 +1,14 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
return ""
|
||||
let counts = {};
|
||||
Array.from(text).forEach((count) => {
|
||||
counts[count] = (counts[count] || 0) + 1;
|
||||
});
|
||||
|
||||
const maxVal = Math.max(...Object.values(counts));
|
||||
const num = Object.keys(counts).find((key) => {
|
||||
return counts[key] === maxVal;
|
||||
});
|
||||
|
||||
return num;
|
||||
}
|
Loading…
Reference in New Issue
Block a user