forked from M3-Academy/challenge-algorithms-v2.0
22 lines
436 B
JavaScript
22 lines
436 B
JavaScript
export function mostUsedChar(text) {
|
|
// implementar logica aqui
|
|
const boxChar = {};
|
|
let max = 0;
|
|
let result = '';
|
|
|
|
for(let char of text){
|
|
if(boxChar[char]){
|
|
boxChar[char]++;
|
|
}else{
|
|
boxChar[char] = 1;
|
|
}
|
|
}
|
|
for(let char in boxChar){
|
|
if(boxChar[char] > max){
|
|
max = boxChar[char];
|
|
result = char;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
} |