Node.js module to calculate mandates using the D'Hondt method.
$ yarn add dhondt-calculator@latest
$ yarn install
$ yarn test
/** This is the class require. */
const { Dhondt } = require('dhondt-calculator');
/** Some test params. */
const votes = [30, 3, 9];
const names = ['A', 'B', 'C'];
const options = {
mandates: 3,
blankVotes: 1,
percentage: 2.6
};
/** This is the instance */
const dhondt = new Dhondt(votes, names, options);
Once you have created the instance, then:
const result = await dhondt.computeWithPromise();
Once you have created the instance, then:
dhondt.computeWithCallback((err, result) => {});
Once you have created the instance, then:
dhondt.computeWithPromise()
.then(result => {})
.catch(error => {});
const result = dhondt.compute();
- votes
number[]
the votes of each party. - names
string[]
the names of the parties. - options
{blankVotes: number, percentage: number, mandates: number}
the constructor options.
- If all went fine with the above example, it outputs:
{
numberOfVotes: 43,
minNumberOfVotes: 2,
parties: { A: 3, B: 0, C: 0 }
}