2022-10-27 15:07:13 +00:00
|
|
|
export function mostUsedChar(text) {
|
|
|
|
// implementar logica aqui
|
2022-11-02 20:53:44 +00:00
|
|
|
const total = text.split("");
|
|
|
|
|
|
|
|
let timesRepeat = {};
|
|
|
|
total.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;
|
|
|
|
}
|
|
|
|
console.log(mostUsedChar("fdgdfgff"))//("f")
|
|
|
|
console.log(mostUsedChar("Lorem ipsum"))//("m")
|
|
|
|
console.log(mostUsedChar("adsassdasd"))//("s")
|
|
|
|
console.log(mostUsedChar("testeeeee"))//("e")
|