From eac3bbdc0a85e1fdf0d0c9d9b3c460e804d54946 Mon Sep 17 00:00:00 2001 From: WillSimao Date: Sat, 29 Oct 2022 20:28:35 -0300 Subject: [PATCH] feat(isAnagram): Finaliza algoritmo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Estou reutilizando esse algoritmo, do meu projeto antigo, provisóriamente pois acredito que não estou usando boas práticas --- 08-isAnagram/index.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 6c9c73a..98f98ff 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,16 +1,6 @@ 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 + return word1.toLowerCase().split("").sort().join() === word2.toLowerCase().split("").sort().join(); + + + }