challenge-algorithms-Ana-Ca.../08-anagrama/index.html

41 lines
1.2 KiB
HTML
Raw Permalink Normal View History

2021-08-18 21:12:18 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
/*
Faça um algoritmo que retorne se um palavra é anagram da outra
*/
function isAnagram(test, original) {
// implementar logica aqui
const Anagram = str =>
str
.toLowerCase()
.replace(/[^a-z0-9]/gi, '')
.split('')
.sort()
.join('');
return Anagram(test) === Anagram(original);
2021-08-18 21:12:18 +00:00
}
// Resultados esperados
console.log(isAnagram("foefet", "toffee"), true) // true
console.log(isAnagram("Buckethead", "DeathCubeK"), true) // true
console.log(isAnagram("Twoo", "WooT"), true) // true
console.log(isAnagram("dumble", "bumble"), false) // false
console.log(isAnagram("ound", "round"), false) // false
console.log(isAnagram("apple", "pale"), false) // false
</script>
</body>
</html>