feat(mostRepeatedChar): Adiciona a logica do algoritmo que retorna a letra mais repetida de uma string

This commit is contained in:
Amanda de Almeida Fonseca 2022-10-28 15:35:20 -03:00
parent 89b3ba787a
commit 83b587aa86

View File

@ -1,4 +1,14 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui // 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;
} }