UNPKG

highest-averages

Version:

Zero-dependency and extensible set of highest averages methods for allocating seats in a parliament. ### Install ```shell npm i highest-averages ``` ### Pure Example - Define the candidates with their vote ```typescript const a = new Candidate('A', 200) c

19 lines (18 loc) 865 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SanMarino2019 = void 0; const dhondt_1 = require("../dhondt"); const political_party_1 = require("../models/political_party"); // TODO: second round conditions // https://en.wikipedia.org/wiki/2019_San_Marino_general_election class SanMarino2019 { dhondt = (new dhondt_1.DHondt); seat = 60; apply(candidates) { const partyCount = candidates.filter(candidate => candidate instanceof political_party_1.PoliticalParty).length; const totalVote = candidates.sumOf(candidate => candidate.vote); candidates.forEach(candidate => candidate.selectable = candidate.vote / totalVote >= Math.max(partyCount * 0.4, 3.5) / 100); return this.dhondt.withSeat(this.seat).withCandidates(candidates).apply(); } } exports.SanMarino2019 = SanMarino2019;