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 +++++++++++++++++++++++++++++++++ graphs/js/intergalactic/travelers.js | 40 ++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 graphs/js/intergalactic/destinations.js create mode 100644 graphs/js/intergalactic/travelers.js (limited to 'graphs/js/intergalactic') 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, +}; diff --git a/graphs/js/intergalactic/travelers.js b/graphs/js/intergalactic/travelers.js new file mode 100644 index 0000000..b806883 --- /dev/null +++ b/graphs/js/intergalactic/travelers.js @@ -0,0 +1,40 @@ +function addTraveler(travelers, firstname, lastname) { + const vip = /(.*[jJ].*[sS].*)|(.*[sS].*[jJ].*)/; + const fullname = firstname + " " + lastname; + + if (travelers.length >= 8) { + console.log(fullname); + if (vip.test(fullname)) { + const last_i = travelers.findLastIndex( + (element) => !vip.test(element), + ); + + if (last_i === -1) { + return false; + } + + travelers.splice(last_i, 1); + } else { + return false; + } + } + + travelers.push(fullname); + return true; +} +function deleteTraveler(travelers, firstname, lastname) { + const fullname = firstname + " " + lastname; + const i = travelers.indexOf(fullname); + + if (i === -1) { + return false; + } + + travelers.splice(i, 1); + return true; +} + +module.exports = { + addTraveler, + deleteTraveler, +}; -- cgit v1.2.3