-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram_18.js
22 lines (22 loc) · 1.62 KB
/
program_18.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"use strict";
// Seeing the World: Think of at least five places in the world you’d like to visit.
// Store the locations in a array. Make sure the array is not in alphabetical order.
let countries = ["Pakistan", "Switzerland", "Australia", "Japan"];
// • Print your array in its original order.
console.log("Original State", countries);
// • Print your array in alphabetical order without modifying the actual list.
console.log("Sort in alphabetical order", [...countries].sort());
// • Show that your array is still in its original order by printing it.
console.log("Original State", countries);
// • Print your array in reverse alphabetical order without changing the order of the original list.
console.log("Reverse alphabetic order", [...countries].sort().reverse());
// • Show that your array is still in its original order by printing it again.
console.log("Original State", countries);
// • Reverse the order of your list. Print the array to show that its order has changed.
console.log("Order is change to reverse", countries.reverse());
// • Reverse the order of your list again. Print the list to show it’s back to its original order.
console.log("Order is change to reverse again", countries.reverse());
// • Sort your array so it’s stored in alphabetical order. Print the array to show that its order has been changed.
console.log("Order is change to alphabetic order", countries.sort());
// • Sort to change your array so it’s stored in reverse alphabetical order. Print the list to show that its order has changed.
console.log("Order is change to alphabetic order again", countries.sort((a, b) => b.localeCompare(a)));