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

23 lines (22 loc) 923 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Dutch2021 = exports.Dutch2017 = void 0; const invalid_votes_1 = require("../models/invalid_votes"); const dhondt_1 = require("../dhondt"); // https://en.wikipedia.org/wiki/2017_Dutch_general_election class Dutch2017 { dhondt = (new dhondt_1.DHondt); seat = 150; apply(candidates) { const totalValidVote = candidates .filter(candidate => !(candidate instanceof invalid_votes_1.InvalidVotes)) .sumOf(candidate => candidate.vote); candidates.forEach(candidate => candidate.selectable = candidate.vote / totalValidVote >= 1 / this.seat); return this.dhondt.withSeat(this.seat).withCandidates(candidates).apply(); } } exports.Dutch2017 = Dutch2017; // https://en.wikipedia.org/wiki/2021_Dutch_general_election class Dutch2021 extends Dutch2017 { } exports.Dutch2021 = Dutch2021;