From dffee7f77e025d55396e2f6435c82c9756595aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Gabriel?= <=> Date: Fri, 28 Oct 2022 08:15:02 -0300 Subject: [PATCH] =?UTF-8?q?feat(isAnagram):=20Feito=20o=20oitavo=20exerc?= =?UTF-8?q?=C3=ADcio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 08-isAnagram/index.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) 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