Skip to content

Commit

Permalink
Presidential election state machine.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Oct 27, 2024
1 parent d626226 commit 6717329
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions presidential-election.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 6717329

Please sign in to comment.