feat: criação da resposta do 09-mostRepeatedChar

This commit is contained in:
Matheus Mariosa 2022-11-02 13:24:45 -03:00
parent 39515dd047
commit 614bead0f7

View File

@ -1,4 +1,22 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui // implementar logica aqui
return "" 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;
} }