feature: resolve exercício 09-mostRepeatedChar

This commit is contained in:
Andrea Matsunaga 2022-10-30 16:42:01 -03:00
parent 26ec68f084
commit 32929413f6

View File

@ -1,4 +1,18 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
let charObj = {};
let maxCount = 0;
let maxChar = "";
for (let char of text) {
charObj[char] = ++charObj[char] || 1;
}
for (let char in charObj) {
if (charObj[char] > maxCount) {
maxCount = charObj[char];
maxChar = char;
}
}
return maxChar;
}