challenge-algorithms-v2.0/09-mostRepeatedChar/index.js

17 lines
555 B
JavaScript
Raw Normal View History

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"))