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/travelers.js | |
add: graphs et rushs
Diffstat (limited to 'graphs/js/intergalactic/travelers.js')
| -rw-r--r-- | graphs/js/intergalactic/travelers.js | 40 |
1 files changed, 40 insertions, 0 deletions
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, +}; |
