An implementation of the Hare-Niemeyer (also known as Hamilton or largest remainder) method. Parliament seat allocation algorithm used in multiple countries around the world.
Attention: Since some countries use a modification of the algorithm instead of this vanilla version, you should check your country's electoral legislature. Furthermore, I don't take any responsibility for the accuracy of the calculated numbers, even though I'm pretty confident with my implementation.
npm install --save hare-niemeyer
const hareNiemeyer =const electionResults = // number of votes per partysocialists: 130755conservatives: 102068liberals: 34012greens: 31090crazypeople: 11111const seats = 420 // number of seats to be distributedconst parliament =
parliament variable will look like this:
draw option changes the behaviour of the algorithm in case of equal quota remainders for multiple parties. Usually, in this case the elections administrator would draw by lot which party gets the remaining seat. The script does this for you if the
draw option is
true or not set at all (default behaviour). If you change the option to
false, the script will return the raw quotas for the involved parties instead:
const electionResults = // number of votes per partysocialists: 10conservatives: 15liberals: 1greens: 4const seats = 100 // number of seats to be distributedconst parliament =
In this case, the
parliament variable looks like this:
If you found a bug, want to propose a feature or feel the urge to complain about your life, feel free to visit the issues page.