diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..c73b1e6 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,22 @@ export function isAnagram(word1, word2) { - // implementar logica aqui - -} \ No newline at end of file + let word1Lower = Array.from(word1.toLowerCase()); + let word2Lower = Array.from(word2.toLowerCase()); + if (word1Lower.length !== word2Lower.length) { + return false; + } + let contador = 0; + while (word1.length !== contador) { + let letraword2 = word2Lower[0]; + if (word1Lower.indexOf(letraword2) !== -1) { + let indice = word1Lower.indexOf(letraword2); + word1Lower.splice(indice, 1); + word2Lower.shift(); + } + contador = contador + 1; + } + if (word1Lower.length === 0 && word2Lower.length === 0) { + return true; + } else { + return false; + } +}