2022-10-27 15:07:13 +00:00
|
|
|
export function mostUsedChar(text) {
|
|
|
|
// implementar logica aqui
|
2022-11-02 23:13:05 +00:00
|
|
|
const total = text.split("");
|
|
|
|
|
|
|
|
let stringRepeat = {};
|
|
|
|
total.forEach((count) => {
|
|
|
|
stringRepeat[count] = (stringRepeat[count] || 0) + 1;
|
|
|
|
})
|
|
|
|
|
|
|
|
const maxVal = Math.max(...Object.values(stringRepeat));
|
|
|
|
const num = Object.keys(stringRepeat).find((key) => stringRepeat[key] === maxVal);
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
console.log(mostUsedChar("fdgdfgff"))
|
|
|
|
console.log(mostUsedChar("Lorem ipsum"))
|
|
|
|
console.log(mostUsedChar("adsassdasd"))
|
|
|
|
console.log(mostUsedChar("testeeeee"))
|