feat: Resolve o exercício 08-isAnagram

This commit is contained in:
SamuelCondack 2022-10-27 17:37:29 -03:00
parent bd7262fc36
commit 3e366ffee8
2 changed files with 13 additions and 6 deletions

View File

@ -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('')
}

View File

@ -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);
});
});