diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..94f5f95 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,23 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" -} \ No newline at end of file + let arr = [] + + for (let i = 0; i < text.length; i++) { + arr.push(text[i]) + } + + let counts = {} + + arr.forEach(count => { + counts[count] = (counts[count] || 0) + 1 + }) + + const maxValue = Math.max(...Object.values(counts)) + const mostUsed = Object.keys(counts).find((key) => { + return counts[key] === maxValue + }) + + return mostUsed +} + +mostUsedChar('banana') \ No newline at end of file