UNPKG

ecclesia

Version:

Framework for political and electoral simulations

37 lines (36 loc) 978 B
// src/actors/vote.ts var Vote = class _Vote { constructor(votesFor, votesAgainst) { this.votesFor = votesFor; this.votesAgainst = votesAgainst; } /** * Returns the reverse of the vote, inverting the for/against ratio. * Simulates a vote on the opposite motion. */ get neg() { return new _Vote(this.votesAgainst, this.votesFor); } get votesCast() { return this.votesFor + this.votesAgainst; } /** * Returns the ratio of votes for over the total number of votes cast. * If there are no votes cast, returns an Infinity. */ get ratio() { return this.votesFor / this.votesCast; } /** * Returns the votes in order of decreasing ratio. * The ties are ordered by decreasing number of positive votes, * and then by the order they came in. */ static order(votes) { return votes.sort((a, b) => b.ratio - a.ratio || b.votesFor - a.votesFor); } }; export { Vote }; //# sourceMappingURL=chunk-QR5MPQNM.js.map