New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rcv

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rcv - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

readme.md

24

lib/irv.js

@@ -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));

2

package.json
{
"name": "rcv",
"version": "0.0.0",
"version": "0.1.0",
"description": "Implementation of ranked choice voting methods",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc