feat: Resolve o exercício 08-isAnagram
This commit is contained in:
parent
bd7262fc36
commit
3e366ffee8
@ -1,4 +1,11 @@
|
|||||||
export function isAnagram(word1, word2) {
|
export function isAnagram(word1, word2) {
|
||||||
// implementar logica aqui
|
// 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('')
|
||||||
}
|
}
|
@ -5,23 +5,23 @@ describe("isAnagram", () => {
|
|||||||
expect(isAnagram("roma", "amor")).toBe(true);
|
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);
|
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);
|
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);
|
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);
|
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);
|
expect(isAnagram("apple", "pale")).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user