diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..316aef4 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,21 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" -} \ No newline at end of file + // implementar logica aqui + let palavra = text.toLowerCase().split("").sort(); + let i, + j, + k = 0; + let maisRepetido; + for (i in palavra) { + let char = palavra[i]; + if (char === palavra[i - 1]) { + j++; + if (j > k) { + k = j; + maisRepetido = palavra[i]; + } + } else { + j = 0; + } + } + return maisRepetido; +}