An implementation of the Sainte-Laguë (also known as Webster or Schepers) method. Parliament seat allocation algorithm used in multiple countries such as Germany, Latvia, New Zealand etc…
Attention: Since some countries (like Latvia or Norway) 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 sainte-lague
const sainteLague =const electionResults = // number of votes per partysocialists: 130755conservatives: 102068liberals: 34012greens: 31090crazypeople: 11111const seats = 420 // number of seats to be distributedconst opt = // options, can be nulldraw: false // if a draw would be necessary to determine the seat count (e.g. 11 seats and two parties with 100 votes each), the library will throw an error, unless you set draw: true, in which case it will assert the ambiguous seat(s) randomlyconst parliament =
parliament variable will look like this:
If you found a bug or want to propose a feature, feel free to visit the issues page.