Anagram with JS
Check Whether the given String is Anagram or Not?
Video link: https://youtube.com/shorts/WN3ja7VBdbQ?feature=share
What is Anagram?
--> An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, "abcd" and "dacb" are an anagram of each other.
HTML CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Coder Anamika</title>
</head>
<body>
<h1>Check whether a string is Anagram or Not</h1>
</body>
<script src="anagram.js"></script>
</html>
JS CODE:
function checkAnagram(str1 , str2){
if(sorting(str1) == sorting(str2)){
console.log(`Yes ${str1} and ${str2} is Anagram!`)
}
else{
console.log(`No ${str1} and ${str2} is not Anagram!`)
}
}
function sorting(str) {
return str.split('').sort().join();
}
checkAnagram('abcd' , 'dacb')
checkAnagram('abcd' , 'decb')
checkAnagram('abqd' , 'daob')

Comments
Post a Comment