Skip to content

lzear/votes

Repository files navigation

votes

version npm bundle size language downloads last commit Libraries.io dependency status for latest release license Build Status Codacy Badge Codacy Badge CodeClimate Coverage CodeClimate Maintainability Code Climate technical debt CodeFactor codecov npms.io (final) npms.io (final) Website

🧑‍💻 Install

yarn add votes

🗳️ Use

import { Borda } from 'votes'

const borda = new Borda({
  candidates: ['Lion', 'Bear', 'Sheep'],
  ballots: [
    { ranking: [['Lion'], ['Bear'], ['Sheep']], weight: 4 },
    { ranking: [['Sheep'], ['Bear'], ['Lion']], weight: 3 },
    { ranking: [['Bear', 'Sheep'], ['Lion']], weight: 2 },
  ],
})

const scores = borda.scores()
// -> { Bear: 10, Lion: 8, Sheep: 9}

const ranking = borda.ranking()
// -> [ [ 'Bear' ], [ 'Sheep' ], [ 'Lion' ] ]

📚 Documentation

📊 Voting systems

Absolute majority: Checks if a candidate is ranked first by more than 50% of voters.

Approval voting: Each voter can select (“approve”) any number of candidates. The winner is the most-approved candidate.

Baldwin method: Iterative Borda count in which, each round, candidates scoring the lowest score are eliminated.

Borda count: For each voter, every candidate is given a number of points which equals the number of candidates ranked lower in the voter's preference.

Bottom-two-runoff: take the two options with the fewest first preference votes. The pairwise loser out of those two options is eliminated. Repeat.

Contingent vote (immediate Two-round system): If no candidate receives 50% of the votes in the first round, then a second round of voting is held with only the top two candidates.

Coombs' method: Each round, the candidate with the most last rank is eliminated. The election repeats until there is a winner.

Copeland's method: Rank candidates by number of duels won against other candidates.

Instant-runoff: Considering only the top choice of each voter, the candidate with the fewest votes is eliminated. The election repeats until there is a winner. This voting system is very similar to single transferable vote method.

Kemeny–Young method: A relatively complex computation generating a preference order aiming to minimize dissatisfaction of the voters. Also known as Kemeny rule, VoteFair popularity ranking, the maximum likelihood method, and the median relation.

Maximal lotteries & Randomized Condorcet: Returns probabilities for each candidate that should be used for a lottery between the Candidates. If a candidate is the Condorcet winner, its probability will be 1. Despite being non-deterministic, those methods are the fairest. Currently, these methods give incorrect results in many cases because of mistakes in the codes!

Majority Judgement: (⚠️ cardinal voting system). Voters can rank candidates in an array corresponding to 6 categories ("Excellent", "Very good", "Good", "Passable", "Mediocre" and "Bad"). Candidates with the best median are ranked first.

Minimax Condorcet method: Ranking the candidates by smallest pairwise defeat.

Minimax-TD: Compute the Smith set . Then compute the Minimax ranking on that set. TD stands for Tideman-Darlington.

Nanson method: Iterative Borda count in which, each round, candidates scoring the average score or less are eliminated.

Plurality: Simple voting method where only the preferred candidate of each voter gets 1 point. AKA first-past-the-post.

Random candidate: Selects a random ranking, regardless of ballots.

Random dictator: Selects a random ballot that decides the ranking.

Ranked pairs: Using the duel results as edges, build an acyclic graph starting by the strongest score differences. The roots of the graph are the winners.

Schulze method: From the votes, compute the results of all possible duels. Then remove the most indecisive (closest to 50/50) duels until there is an undefeated candidate, the winner. This popular voting system is used by several organizations (Ubuntu, Debian, Wikimedia...).

Smith's method: All members of the top cycle (a.k.a. Smith set): "the smallest non-empty set of candidates in a particular election such that each member defeats every candidate outside the set in a pairwise election"

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

The repository is split in 2 projects:

  • /votes contains the source of the NPM package votes

  • /demo contains the source of the demo website