diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index 5ccb7f5..8b57af2 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,12 +1,21 @@ - - // implementar logica aqui - export function mostUsedChar(text){ - const charMap = {}; - - for (const char of text.toLowerCase()) { - /*5*/ charMap[char] = (charMap[char] || 0) + 1; - } - - return Object.values(charMap).filter((count) => count > 1).length; - } - +export function mostUsedChar(text) { + // implementar logica aqui + const stringToArray = text.split('') + const obj = {} + + stringToArray.forEach(element => { + obj[element] = obj[element] ? obj[element] + 1 : 1 + }) + + const objToArray = Object.entries(obj) + + let res = ['', 0] + + objToArray.forEach(word => { + if (res[1] < word[1]) { + res = word + } + }) + + return res[0] +}