D'Hondt calculator
Node.js module to calculate mandates using the D'Hondt method.
Install
$ npm install dhondt-calculator@latest --save
Test
$ sudo npm install -g typescript@latest$ npm install$ npm test
Create an instance
/** This is the class require. */const Dhondt = ; /** Some test params. */const votes = 30 3 9;const names = 'A' 'B' 'C';const options = mandates: 3 blankVotes: 1 percentage: 26; /** This is the instance */const dhondt = votes names options;
Usage with async+await (async)
Once you have created the instance, then:
const result = await dhondt;
Usage with callback (async)
Once you have created the instance, then:
dhondt;
Usage with classic promises (async)
Once you have created the instance, then:
dhondt ;
Usage without callback (sync)
const result = dhondt;
Constructor Params
- votes
number[]
the votes of each party. - names
string[]
the names of the parties. - options
{blankVotes: number, percentage: number, mandates: number}
the constructor options.
Output
- If all went fine with the above example, it outputs:
numberOfVotes: 43 minNumberOfVotes: 2 parties: A: 3 B: 0 C: 0