diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..12c72d9 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,15 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const value = text.toLocaleLowerCase().split("").sort(); + + let counts = {}; + value.forEach(function (x) { + counts[x] = (counts[x] || 0) + 1; + }); + + const maior = Object.keys(counts).sort(function (a, b) { + return counts[a] > counts[b] ? -1 : counts[b] > counts[a] ? 1 : 0; + })[0]; + + return maior; } \ No newline at end of file