-
Notifications
You must be signed in to change notification settings - Fork 0
/
17-shrinking-guest-list.mjs
44 lines (34 loc) · 982 Bytes
/
17-shrinking-guest-list.mjs
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
const guests = ["Jamaal", "Kamaal", "Nehaal"];
function sendInvite() {
guests.forEach((guest, i) => {
console.log(
`Invite ${i + 1}: `,
`Hi ${guest}, I hope you are doing well. I would like to invite you to the dinner tomorrow.`
);
});
}
console.log(
"Hey Friends! We have a bigger table and 3 more guests are joining us!"
);
guests.unshift("Bilal");
const middleIndexOfArray = Math.ceil(guests.length / 2);
guests.splice(middleIndexOfArray, 0, "Faheem");
guests.push("Shabbir");
sendInvite();
console.log(
"Hey Friends! There is a BAD news. The table will not arrive in time, so we can only invite 2 more guests!"
);
function removeGuest() {
if (guests.length > 2) {
const guest = guests.pop();
console.log(
`Hi ${guest}! Sorry to say but due to odd circumstances, I can't invite you to the dinner.`
);
removeGuest();
}
}
removeGuest();
sendInvite();
guests.pop();
guests.pop();
console.log(`Guests Array: `, guests);