summaryrefslogtreecommitdiff
path: root/graphs/js/intergalactic
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/js/intergalactic
add: graphs et rushs
Diffstat (limited to 'graphs/js/intergalactic')
-rw-r--r--graphs/js/intergalactic/destinations.js47
-rw-r--r--graphs/js/intergalactic/travelers.js40
2 files changed, 87 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,
+};
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,
+};