feat(09-mostRepeatedChar): Adiciona função

This commit is contained in:
Emerson Fully 2022-10-30 19:40:31 -03:00
parent d32e6541d3
commit 0eecc63f1c

View File

@ -1,4 +1,23 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
const charMap = {};
let max = 0;
let frequentChar = '';
for (let char of text) {
if (charMap[char]){
charMap[char]++;
} else {
charMap[char] = 1;
}
}
for (let char in charMap) {
if (charMap[char] > max) {
max = charMap[char];
frequentChar = char;
}
}
return frequentChar
}