We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7152052 commit a06d8b4Copy full SHA for a06d8b4
Anagram.js
@@ -0,0 +1,35 @@
1
+// Approach 1
2
+function Anagram(str1, str2) {
3
+ if (str1.length !== str2.length) {
4
+ return false;
5
+ }
6
+ let str11 = str1.split("").sort().join("");
7
+ let str22 = str2.split("").sort().join("");
8
+ if (str11 === str22) {
9
+ return true;
10
11
12
+}
13
+
14
+console.log(Anagram("namit", "timen"));
15
16
+// Approach 2
17
+const CHAR = 256;
18
19
+ const charArray = new Array(CHAR).fill(0);
20
21
22
23
24
+ for (let i = 0; i < str1.length; i++) {
25
+ charArray[str1.charCodeAt(i)]++;
26
+ charArray[str2.charCodeAt(i)]--;
27
28
29
+ for (let i = 0; i < CHAR; i++) {
30
+ if (charArray[i] !== 0) return false;
31
32
33
34
35
+console.log(Anagram("triangle", "integral"));
0 commit comments