diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..be923f9 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,21 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + let SIZE = 256 + let count = new Array(SIZE); + for (let n = 0; n < SIZE; n++) { + count[n] = 0; + } + let len = text.length; + for (let i = 0; i < len; i++) { + count[text[i].charCodeAt(0)] += 1; + } + let max = -1; + let result = ' '; + for (let i = 0; i < len; i++) { + if (max < count[text[i].charCodeAt(0)]) { + max = count[text[i].charCodeAt(0)]; + result = text[i]; + } + } + return result; } \ No newline at end of file