JS implementation of Schulze method for your Condorcet election method.
Try It OnlineGithub RepoSchulze.js is an open source MIT License JS implementation of the electoral system Schulze method, which is one of the Condorcet election method that elects the candidate that would win a majority of the vote in all of the head-to-head elections against each of the other candidates, whenever there is such a candidate.
Schulze.js is available both for browser or Node.js.
Simply download schulze.js or schulze.min.js from github and include it in your html:
First install this module:
Then, require it in your script:
Say you have a form of scores for candidates provided by different judges looking like this:
And it's stored in either CSV format or a 2D Array:
You can calculate the rank with Schulze method by passing the data into following functions:
the returned value is an object with two members rank
and detail
:
list of objects for each candidates. Each object contains following fields
idx
- original index in datacount
- count of winning vote against othersrank
- rank in all candidatesname
- name of candidatecount of winning votes for every candidate against other candidates.
Schulze.js provides a handy toCsv
function for you to generate result in CSV:
where rank
is the rank member of returned object generated by fromCsv
or fromArray
function calls.
Schulze.js provides some additional configurations so you can tweak its behavior based on your input and desired output.
Input options are available in fromCsv
and fromArray
.
isRowBased
- see next section. default true
isRank
- is input data actually ranking order. default false
higherIsBetter
- is higher input value means better in score. default true
Output options are available in toCsv
function.
sort
- sort result based on ranking. default false
.While not yet available, it's possible to use Schulze.js as a google sheet function once you install it after the extension get approved by Google team. To use it, call the function "schulze" with following parameters:
input
- Range of the above data, such as "A1:E7"isRowBased
- default true. only set it to false if you got your data transposed.isRank
- set to true if the values are rank instead of score, otherwise false.higherIsBetter
- set to true if higher score means better, otherwise false.here is an example of the usage and corresponding result:
=schulze(B2:E8,true,false,true)
If you don't know how to use spreadsheet function, you can still compute the schulze rank by
Add-ons
→ Condorcet
→ Condorcet / Schulze Mtehod
This library is open sourced under MIT License. Source code can be found in its Github Repository. For bug reports, pull requests or feature suggestions, please also firing issues / pull requests in the repository.