diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/js/intergalactic/destinations.js | |
add: graphs et rushs
Diffstat (limited to 'graphs/js/intergalactic/destinations.js')
| -rw-r--r-- | graphs/js/intergalactic/destinations.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/graphs/js/intergalactic/destinations.js b/graphs/js/intergalactic/destinations.js new file mode 100644 index 0000000..c184458 --- /dev/null +++ b/graphs/js/intergalactic/destinations.js @@ -0,0 +1,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, +}; |
