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

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;
}