From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/js/intergalactic/destinations.js | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 graphs/js/intergalactic/destinations.js (limited to 'graphs/js/intergalactic/destinations.js') 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, +}; -- cgit v1.2.3