18 lines
508 B
JavaScript
18 lines
508 B
JavaScript
export function mostUsedChar(text) {
|
|
const total = text.split("");
|
|
|
|
let repeat = {};
|
|
total.forEach((count) => {
|
|
repeat[count] = (repeat[count] || 0) + 1;
|
|
});
|
|
|
|
const maxVal = Math.max(...Object.values(repeat));
|
|
const num = Object.keys(repeat).find((key) => repeat[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")
|