We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 8243884 + da0f3d5 commit 83bd715Copy full SHA for 83bd715
strings/anagram.js
@@ -0,0 +1,9 @@
1
+//Check if 2 words are anagrams of each other.
2
+var o1 = "arms";
3
+var o2 = "mars"
4
+//Remove non-letter characters, and sort the letters in alphabetical order.
5
+var n1 = o1.replace(/\W+/g,'').toLowerCase().split("").sort().join("");
6
+var n2 = o2.replace(/\W+/g,'').toLowerCase().split("").sort().join("");
7
+var isAnagram = n1==n2;
8
+if(isAnagram) console.log("The two words are anagrams");
9
+else console.log("The two words are not anagrams");
0 commit comments