-
Notifications
You must be signed in to change notification settings - Fork 0
/
19.js
99 lines (83 loc) · 2.54 KB
/
19.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
let names = ["Shamsa", "Abdullah", "Haris", "Talha"];
let names_length = names.length;
var text = "";
console.log(text);
result = invitation(names_length, names);
console.log(result);
console.log(names[0] + " will not make it.");
const index = names.indexOf("Saad"); // 👉️ 0
if (index !== -1) {
names[index] = "Raza";
}
console.log("New List:");
console.log(names);
new_result = invitation(names_length, names);
console.log("New Invitations:");
console.log(new_result);
const new_names = ["Shamsa", "Ahmed", "Sameer"];
console.log("\n New Guests Names:");
console.log(new_names);
names.unshift(new_names[0]);
names.splice(3, 0, new_names[1]);
names.push(new_names[2]);
console.log(names);
new_names_length = names.length;
final_results = invitation(new_names_length, names);
console.log("\n Final Results:");
console.log(final_results);
/* 17 Answers starts from here */
new_invitation = new_invitation(new_names_length, names);
console.log("\n New invitation Results:");
console.log(new_invitation);
removing_guests_from_invitation = removing_guests_from_invitation(
new_names_length,
names
);
console.log("\n Guest Not Invited and message Printed:");
console.log(removing_guests_from_invitation);
console.log("\n Remaing Guests");
console.log(names);
final_names_length = names.length;
final_invitation = final_invitation(final_names_length, names);
console.log("\n Invited Guests:");
console.log(final_invitation);
console.log("Guests Invited:" + final_names_length);
names = [];
// console.log(' maked sure actually have an empty list at the end of our program.' + names)
function invitation(names_length, names) {
text = "";
for (let i = 0; i < names_length; i++) {
text += "\n" + names[i] + " i would like to invite to dinner.";
}
return text;
}
function new_invitation(names_length, names) {
text = "";
for (let i = 0; i < names_length; i++) {
text +=
"\n" +
names[i] +
" Sorry For inconvenience, But we can only invite two guests :(.";
}
return text;
}
function removing_guests_from_invitation(names_length, names) {
text = "";
names_length = names_length - 2;
for (let i = 0; i < names_length; i++) {
text +=
"\n Hi " +
names[i] +
"! Sorry For inconvenience, But due to limited space you can’t be invited :(.";
names.splice(names[i], 1);
}
return text;
}
function final_invitation(names_length, names) {
text = "";
console.log(names_length);
for (let i = 0; i < names_length; i++) {
text += "\n Hi " + names[i] + "! Congratulations You are invited :(.";
}
return text;
}