From f748d31ad5c75ea07692cb4f49431844aba16862 Mon Sep 17 00:00:00 2001 From: WillSimao Date: Sat, 29 Oct 2022 02:05:24 -0300 Subject: [PATCH] feat(isAnagram): Finaliza algoritmo --- 08-isAnagram/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..6c9c73a 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,16 @@ export function isAnagram(word1, word2) { // implementar logica aqui + + const word2Arr = word2.toLowerCase().split(''); + + for(let i = 0; i < word1.length; i++) { + + const index = word2Arr.indexOf(word1.toLowerCase()[i]); + + if(index === -1) return false; + word2Arr.splice(index, 1); + } + + return !word2Arr.length; } \ No newline at end of file