From 67173299160a0a8eefcd66b73d0c6346e4710453 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 27 Oct 2024 02:04:53 +0000 Subject: [PATCH] Presidential election state machine. --- presidential-election.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 presidential-election.js diff --git a/presidential-election.js b/presidential-election.js new file mode 100644 index 0000000..a976f96 --- /dev/null +++ b/presidential-election.js @@ -0,0 +1,29 @@ +const RustCalendar = require('./rust-calendar'); + +function CalculateCurrentStageOfElectionCycle() { + const weekOfMonth = RustCalendar.CalculateCurrentWeekOfTheMonth(); + const weeksThisMonth = RustCalendar.CalculateHowManyThursdaysThisMonth(); + if (weeksThisMonth === 4) { + if (weekOfMonth === 0) return 'presidency'; + if (weekOfMonth === 1) return 'presidency'; + if (weekOfMonth === 2) return 'vacant'; + if (weekOfMonth === 3) return 'election'; + if (weekOfMonth === 4) return 'presidency'; + } + if (weeksThisMonth === 5) { + if (weekOfMonth === 0) return 'presidency'; + if (weekOfMonth === 1) return 'presidency'; + if (weekOfMonth === 2) return 'vacant'; + if (weekOfMonth === 3) return 'vacant'; + if (weekOfMonth === 4) return 'election'; + if (weekOfMonth === 5) return 'presidency'; + } + throw 'Something went wrong with a Rust calendar calculation'; +} + +function Main() { + const stage = CalculateCurrentStageOfElectionCycle(); + console.log(stage); +} + +Main();