Skip to content

Commit

Permalink
Feat: randomly decide which candidates are selected by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaiconstantin committed Nov 28, 2024
1 parent 8e92724 commit c933750
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/calculateVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export const initializeAllocations = (firstCandidate: CandidateProps, secondCand
// Initialize the allocations array.
const allocations: InputProps[] = [];

// Record the IDs to allocate to.
const qualifiedIDs: string[] = qualifiedCandidates.map(c => c.id);

// For each qualified candidate.
qualifiedCandidates.forEach(candidate => {
// Add the initial allocation for the candidate.
Expand All @@ -25,10 +28,13 @@ export const initializeAllocations = (firstCandidate: CandidateProps, secondCand

// For each dropout candidate.
dropoutCandidates.forEach(candidate => {
// Randomly sample which qualified candidate id to use.
const qualifiedCandidateId = qualifiedIDs[Math.floor(Math.random() * qualifiedIDs.length)];

// Add the initial allocation for the candidate.
allocations.push({
from: candidate.id,
to: secondCandidate.id,
to: qualifiedCandidateId,
percentage: 50,
proportion: 0.5
});
Expand Down

0 comments on commit c933750

Please sign in to comment.