From 3e366ffee8774020dba6e59973e1516f7ca03914 Mon Sep 17 00:00:00 2001 From: Samuel Date: Thu, 27 Oct 2022 17:37:29 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20Resolve=20o=20exerc=C3=ADcio=2008-isAna?= =?UTF-8?q?gram?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 08-isAnagram/index.js | 9 ++++++++- 08-isAnagram/index.test.js | 10 +++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..21ae250 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,11 @@ export function isAnagram(word1, word2) { // implementar logica aqui - + word1 = word1.replace(/[^\w]/g, '').toLowerCase() + word2 = word2.replace(/[^\w]/g, '').toLowerCase() + + return sortString(word1) === sortString(word2) +} + +function sortString(string) { + return string.split('').sort().join('') } \ No newline at end of file diff --git a/08-isAnagram/index.test.js b/08-isAnagram/index.test.js index 4d7c8a7..b2998f9 100644 --- a/08-isAnagram/index.test.js +++ b/08-isAnagram/index.test.js @@ -5,23 +5,23 @@ describe("isAnagram", () => { expect(isAnagram("roma", "amor")).toBe(true); }); - ít("Dever retornar true quando passamos as palavras \"Buckethead\" e \"DeathCubeK\"", () => { + it("Dever retornar true quando passamos as palavras \"Buckethead\" e \"DeathCubeK\"", () => { expect(isAnagram("Buckethead", "DeathCubeK")).toBe(true); }); - ít("Dever retornar true quando passamos as palavras \"Twoo\" e \"WooT\"", () => { + it("Dever retornar true quando passamos as palavras \"Twoo\" e \"WooT\"", () => { expect(isAnagram("Twoo", "WooT")).toBe(true); }); - ít("Dever retornar false quando passamos as palavras \"dumble\" e \"bumble\"", () => { + it("Dever retornar false quando passamos as palavras \"dumble\" e \"bumble\"", () => { expect(isAnagram("dumble", "bumble")).toBe(false); }); - ít("Dever retornar false quando passamos as palavras \"ound\" e \"round\"", () => { + it("Dever retornar false quando passamos as palavras \"ound\" e \"round\"", () => { expect(isAnagram("ound", "round")).toBe(false); }); - ít("Dever retornar false quando passamos as palavras \"apple\" e \"pale\"", () => { + it("Dever retornar false quando passamos as palavras \"apple\" e \"pale\"", () => { expect(isAnagram("apple", "pale")).toBe(false); }); }); \ No newline at end of file