diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..bedc121 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,16 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const textObj = {} + let maxCount = 0 + let mostUsedChar = "" + for (let char of text) { + textObj[char] = textObj[char] + 1 || 1 + } + for (let key in textObj) { + if (textObj[key] > maxCount) { + maxCount = textObj[key] + mostUsedChar = key + } + } + return mostUsedChar } \ No newline at end of file