forked from M3-Academy/challenge-algorithms-v2.0
23 lines
463 B
JavaScript
23 lines
463 B
JavaScript
export function mostUsedChar(text) {
|
|
// implementar logica aqui
|
|
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
|
|
} |