diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index f88d9d4..769a312 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -6,17 +6,21 @@ export function isAnagram(word1, word2) { if (word1.toLowerCase().length !== word2.toLowerCase().length) { return false } - for (let i = 0; i < word1.toLowerCase().length; i++) { - let res = word1.toLowerCase().charCodeAt(i) - 97 - array[res] = (array[res] || 0) + 1 - } - - for (let j = 0; j < word2.toLowerCase().length; j++) { - let res = word2.toLowerCase().charCodeAt(j) - 97 - if (!array[res]) { - return false + + else { + + for (let i = 0; i < word1.toLowerCase().length; i++) { + let res = word1.toLowerCase().charCodeAt(i) - 97 + array[res] = (array[res] || 0) + 1 } - array[res]-- + + for (let j = 0; j < word2.toLowerCase().length; j++) { + let res = word2.toLowerCase().charCodeAt(j) - 97 + if (!array[res]) { + return false + } + array[res]-- + } + return true } - return true } diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..5ccb7f5 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,12 @@ -export function mostUsedChar(text) { + // implementar logica aqui - return "" -} \ No newline at end of file + 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; + } +