feat: resolve mostRepeatedChar

This commit is contained in:
Naian Felix dos Santos 2022-10-28 09:28:53 -03:00
parent e50b6fb5ae
commit d68e3bd4d9

View File

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