-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq18.ts
More file actions
46 lines (33 loc) · 1.97 KB
/
q18.ts
File metadata and controls
46 lines (33 loc) · 1.97 KB
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
// Seeing the World: Think of at least five places in the world you’d like to visit.
export default function q18() {
// Store the locations in an array. Make sure the array is not in alphabetical order.
const placesToVisit: string[] = ['Japan', 'Brazil', 'New Zealand', 'Italy', 'Thailand'];
// Print the array in its original order.
console.log('\nOriginal order:');
console.log(placesToVisit);
// Print the array in alphabetical order without modifying the actual list.
console.log('\nAlphabetical order:');
console.log([...placesToVisit].sort());
// Show that the array is still in its original order by printing it.
console.log('\nArray still in original order:');
console.log(placesToVisit);
// Print the array in reverse alphabetical order without changing the order of the original list.
console.log('\nReverse alphabetical order:');
console.log([...placesToVisit].sort().reverse());
// Show that the array is still in its original order by printing it again.
console.log('\nArray still in original order:');
console.log(placesToVisit);
// Reverse the order of the list. Print the array to show that its order has changed.
console.log('\nReversed order:');
console.log([...placesToVisit].reverse());
// Reverse the order of the list again. Print the list to show it’s back to its original order.
console.log('\nBack to original order:');
console.log([...placesToVisit].reverse());
// Sort the array so it’s stored in alphabetical order. Print the array to show that its order has been changed.
console.log('\nAlphabetical order:');
console.log([...placesToVisit].sort());
// Sort to change the array so it’s stored in reverse alphabetical order. Print the list to show that its order has changed.
console.log('\nReverse alphabetical order:');
console.log([...placesToVisit].sort().reverse());
}
q18();