diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..70059cb 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,32 @@ export function isAnagram(word1, word2) { - // implementar logica aqui - + let teste, original, cont1 = 0, cont2 = 0; + + teste = word1.split(""); + original = word2.split(""); + + if (teste.length === original.length) { + for (let i = 0; i < teste.length; i++) { + cont1 = 0; + cont2 = 0 + for (let j = 0; j < teste.length; j++) { + if (teste[i].toUpperCase() === teste[j].toUpperCase()) { + cont1++; + } + } + for (let k = 0; k < original.length; k++) { + if (teste[i].toUpperCase() === original[k].toUpperCase()) { + cont2++; + } + } + + if (cont1 === cont2) { + return true; + } else { + return false; + } + } + } else { + return false + } + } \ No newline at end of file