blob: c184458458aebf252553c6f8a4c8c9974940caa6 (
plain)
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
|
function displayDestinations(destinations) {
if (
!(destinations instanceof Map) ||
destinations == null ||
destinations == undefined ||
destinations.size === 0
) {
console.log("No destination is available.");
} else {
destinations.forEach((v, k) => {
console.log(k + ": " + v);
});
}
}
function addDestination(destinations, name, cost) {
if (
typeof name != "string" ||
typeof cost != "number" ||
cost < 0 ||
destinations.has(name)
) {
return false;
}
destinations.set(name, cost);
return true;
}
function removeDestination(destinations, name) {
if (typeof name != "string" || !destinations.has(name)) {
return false;
} else {
destinations.delete(name);
return true;
}
}
function getDestinationsInOrder(destinations) {
const res = new Array();
destinations.forEach((v, k) => res.push([v, k]));
return res.sort((vkp1, vkp2) => vkp1[0] - vkp2[0]).map((vkp) => vkp[1]);
}
module.exports = {
displayDestinations,
addDestination,
removeDestination,
getDestinationsInOrder,
};
|