diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..e993202 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,23 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const charMap = {}; + let max = 0; + let frequentChar = ''; + + for (let char of text) { + if (charMap[char]){ + charMap[char]++; + } else { + charMap[char] = 1; + } + } + + for (let char in charMap) { + if (charMap[char] > max) { + max = charMap[char]; + frequentChar = char; + } + } + + return frequentChar } \ No newline at end of file