-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
135 lines (118 loc) · 3.52 KB
/
script.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function checkInput() {
var n = document.getElementById("person1").value;
var m=document.getElementById("person2").value;
if (n==="" || m===""){
alert("Please enter both the names");
}
else if(n===m){
alert("Please enter different names");
}
else{
// var n = document.getElementById("person1").value;
n=n.toLowerCase().replace(" ", "");
// var m=document.getElementById("person2").value;
m=m.toLowerCase().replace(" ", "");
console.log(n);
console.log(m);
var game, unique;
if (n.length < m.length) {
unique = get_unique(n, m);
}
else if(n.length > m.length){
unique = get_unique(m, n);
}
else{
unique = get_unique(m, n);
}
console.log("unique : ", unique);
if(unique===0){
alert("No unique letters in the given names. Try entering different names");
}
else{
findFlames(n,m,unique);
}
}
}
// -----------------------------------------------------------------
function resetStuff() {
document.getElementById("person1").value = "";
document.getElementById("person2").value = "";
document.getElementById("result").innerHTML = " ";
}
// -----------------------------------------------------------------
function get_unique(a, b) {
var count;
count = 0;
for (var i = 0, _pj_a = a.length; i < _pj_a; i += 1) {
for (var j = 0, _pj_b = b.length; j < _pj_b; j += 1) {
if (a[i] === b[j]) {
b = b.slice(0, j) + b.slice(j + 1);
count += 1;
break;
}
}
}
console.log("len a [Without Removing duplicates]", a.length);
console.log("count", count);
console.log("leb b [After Removing duplicates]", b.length);
return a.length - count + b.length;
}
// ---------------------------------------------------------------
function findFlames(n,m,unique){
var finalText="";
game = "FLAMES";
function findLEFT(unique, s, position) {
var i, index;
i = 0;
index = -1 + position;
while (i < unique) {
index += 1;
if (index === s.length) {
index = 0;
}
i += 1;
}
if (i === unique) {
return [s.slice(0, index) + s.slice(index + 1), index];
}
}
var game, position;
position = 0;
console.log(`[${game}]`);
while (game.length !== 1) {
[game, position] = findLEFT(unique, game, position);
console.log(`[${game}]`, position);
}
console.log("----------------");
if (game === "F") {
console.log("Friends.");
// finalText += "Friends.";
finalText += "Friends🫂";
}
else if(game === "L") {
console.log("Love.");
// finalText += "Love.";
finalText += "Love ❤";
}
else if(game === "A") {
console.log("Affection.");
// finalText += "Affection.";
finalText += "Affection 🥰";
}
else if(game === "M") {
console.log("Marriage.");
// finalText += "Marriage.";
finalText += "Marriage 💍";
}
else if(game === "E") {
console.log("Enemy.");
// finalText += "Enemy.";
finalText += "Enemy ⚔️";
}
else if(game === "S") {
console.log("Sister.");
// finalText += "Sister.";
finalText += "Sister 👫";
}
document.getElementById("result").innerHTML = finalText;
}