feat(mostrepeatedchar):aplicando a função ao testee 9

This commit is contained in:
Gabriel Bernardini 2022-10-29 12:46:25 -03:00
parent 82e915ce28
commit 3c55eae119

View File

@ -1,4 +1,12 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui // implementar logica aqui
return "" const arr = text.split("");
let counts = {};
arr.forEach((count) => {
counts[count] = (counts[count] || 0) + 1;
});
const maxVal = Math.max(...Object.values(counts));
const num = Object.keys(counts).find((key) => counts[key] === maxVal);
return num;
} }