-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpro18.ts
70 lines (43 loc) · 1.76 KB
/
pro18.ts
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
//seeing the world
let world:string[] =["Paris", "Singapore", "Finland", "Turkey", "England"];
console.log("Original Array", world);
console.log("alphabetical array",world.slice().sort());
console.log("original array",world);
console.log("reverse array",world.slice().sort().reverse());
console.log("original array",world)
world.reverse()
console.log("reverse order is changed",world);
world.reverse()
console.log("order reversed to original",world);
world.sort()
console.log("order changed to alphabetical order",world);
world.sort().reverse()
console.log("order changed to reverse alphabetical order",world);
//question 19
let guest :string[] = ["sohaib", "salman", "hammad"]
guest.forEach(guestlist => {
console.log(`${guestlist} you are invited for dinner with us Today.`);
});
console.log("\t\nNew list\n\t");
//changing in list
let removedGuest = guest.splice(2,2)
guest.push("Ubaid");
guest.forEach(newlist => {
console.log(`${newlist} You are invited for the dinner with us. `);
});
console.log("\t\n \n\t");
guest.unshift("aqib")
guest.push("adnan")
guest.splice(Math.floor(guest.length/2),0, "hussain")
guest.forEach(moreGuest => {
console.log(`${moreGuest} I found a big dining table. lets have a dinner together.`);
});
//shrink guest list
console.log("\n\t \t\n ");
console.log("Sorry we can invite just 2 people because the large table cant be shipped on time");
while (guest.length > 2 ) {
let removedGuest = guest.pop()
console.log(`Sorry ${removedGuest} you are not invited for dinner because of the table issue`)
console.log(`${guest} you are still invited for the dinner`);
}
console.log("Number of people invited for dinner is",guest.length);