forked from dotunlonge/NestLab-Bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion6.js
55 lines (41 loc) · 1.39 KB
/
question6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
let word_one = "Dtoun";
let word_two = "Dotun";
// to be qualified as an anagram, the words must match in length;
// and have the exact words no matter the re-arrangement;
Array.removeSpace = (word) => {
let new_word = "";
for (let i = 0; i < word.length; i++) {
if (word[i] != " ") {
new_word += word[i];
}
}
return new_word;
}
Array.exists = (Arry, word) => {
for (let i = 0; i < Arry.length; i++) {
if (Arry[i] == word) return true;
}
return false;
}
let anagramDetector = ((word1, word2) => {
word1 = Array.removeSpace(Array.from(word1));
word2 = Array.removeSpace(Array.from(word2));
let noticer = 0;
let toHandleRepeatWords = [];
if (word1.length == word2.length) {
for (let i = 0; i < word1.length; i++) {
for (let y = 0; y < word2.length; y++) {
if (word1[i] == word2[y]) {
if (Array.exists(toHandleRepeatWords, word1[i]) == false) {
toHandleRepeatWords.push(word1[i]);
noticer = noticer + 1;
}
}
}
}
if (noticer != word1.length) return console.log("Not An Anagram");
return (console.log("It's An Anagram"));
} else {
return console.log("words not even the same length, cant be an anagram bro");
}
})(word_one, word_two);