Comparing version 0.0.0 to 0.1.0
@@ -18,2 +18,3 @@ let getVotes = c=>c.votes ? c.votes.length : 0; | ||
let votes = reassignee.votes; | ||
if (!votes) return; | ||
votes.forEach(vote=> { | ||
@@ -35,2 +36,23 @@ let choiceIndex = vote.choices.findIndex(c=>c === reassignee.id); | ||
let getState = (candidates) => { | ||
let state = {}; | ||
for (let candidate of candidates) { | ||
let candState = { null: 0 }; | ||
if(!candidate.votes) continue; | ||
candidate.votes.forEach(vote=> { | ||
let choiceIndex = vote.choices.findIndex(c=>c === candidate.id); | ||
for (let nC = choiceIndex+1; nC<vote.choices.length; nC++) { | ||
let nextChoice = candidates.find(c=>c.id === vote.choices[nC]); | ||
if(!nextChoice) continue; | ||
if(!candState[nextChoice.id]) candState[nextChoice.id] = 0; | ||
candState[nextChoice.id] += 1; | ||
return; | ||
} | ||
candState[null] += 1; | ||
}); | ||
state[candidate.id] = candState; | ||
} | ||
return state; | ||
}; | ||
let irv = (initialCandidates, votes)=> { | ||
@@ -44,2 +66,3 @@ let election = { | ||
initialVoteAssign(election.votes, remainingCandidates); | ||
election.stages.push(getState(remainingCandidates)); | ||
while(!majority(remainingCandidates)) { | ||
@@ -49,2 +72,3 @@ var last = getLastPlaceCandidate(remainingCandidates); | ||
reassignVotes(last, remainingCandidates); | ||
election.stages.push(getState(remainingCandidates)); | ||
} | ||
@@ -51,0 +75,0 @@ // console.log(majority(remainingCandidates)); |
{ | ||
"name": "rcv", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "Implementation of ranked choice voting methods", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
6493
5
204
1
5