ecclesia
Version:
Framework for political and electoral simulations
61 lines (60 loc) • 1.96 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/actors/vote.ts
var vote_exports = {};
__export(vote_exports, {
Vote: () => Vote
});
module.exports = __toCommonJS(vote_exports);
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);
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Vote
});
//# sourceMappingURL=vote.cjs.map