2022-10-27 15:07:13 +00:00
|
|
|
export function mostUsedChar(text) {
|
2022-11-02 23:26:52 +00:00
|
|
|
const total = text.split("");
|
2022-11-02 20:53:44 +00:00
|
|
|
|
2022-11-02 23:26:52 +00:00
|
|
|
let repeat = {};
|
|
|
|
total.forEach((count) => {
|
|
|
|
repeat[count] = (repeat[count] || 0) + 1;
|
|
|
|
});
|
2022-11-02 20:53:44 +00:00
|
|
|
|
2022-11-02 23:26:52 +00:00
|
|
|
const maxVal = Math.max(...Object.values(repeat));
|
|
|
|
const num = Object.keys(repeat).find((key) => repeat[key] === maxVal);
|
|
|
|
return num;
|
2022-11-02 20:53:44 +00:00
|
|
|
}
|
2022-11-02 23:26:52 +00:00
|
|
|
|
|
|
|
console.log(mostUsedChar("fdgdfgff")); //("f")
|
|
|
|
console.log(mostUsedChar("Lorem ipsum")); //("m")
|
|
|
|
console.log(mostUsedChar("adsassdasd")); //("s")
|
|
|
|
console.log(mostUsedChar("testeeeee")); //("e")
|