forked from M3-Academy/challenge-algorithms-v2.0
feat: criação da resposta do 09-mostRepeatedChar
This commit is contained in:
parent
39515dd047
commit
614bead0f7
@ -1,4 +1,22 @@
|
||||
export function mostUsedChar(text) {
|
||||
// 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user