diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..52eb7de 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -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; } \ No newline at end of file