mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-02-17 01:12:20 +00:00
Fix map ranking
This commit is contained in:
parent
b1f7aefe46
commit
6481da2270
2 changed files with 12 additions and 1 deletions
|
@ -930,6 +930,7 @@ var CompletedGather = React.createClass({
|
|||
});
|
||||
|
||||
var GatherVotingResults = React.createClass({
|
||||
// Returns an array of ids voted for e.g. [1,2,5,1,1,3,2]
|
||||
countVotes(voteType) {
|
||||
return this.props.gather.gatherers.reduce((acc, gatherer) => {
|
||||
let votes = gatherer[voteType];
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
// Accepts an array of IDs voted
|
||||
// 1. Creates an array of tally objects,
|
||||
// with ID as prop and vote count as val { 12: 0 }
|
||||
// 2. Increments ID vote tally for every vote
|
||||
// 3. Sorts
|
||||
|
||||
var rankVotes = function (votes, candidates) {
|
||||
var initial = candidates.reduce(function (acc, candidate) {
|
||||
acc[candidate.id] = 0;
|
||||
|
@ -25,7 +31,11 @@ var rankVotes = function (votes, candidates) {
|
|||
}
|
||||
|
||||
return rank.sort(function (a, b) {
|
||||
return b.count - a.count;
|
||||
if (b.count === a.count) {
|
||||
return b.id - a.id;
|
||||
} else {
|
||||
return b.count - a.count;
|
||||
}
|
||||
}).map(function (tally) {
|
||||
return tally.id
|
||||
}).map(function (id) {
|
||||
|
|
Loading…
Reference in a new issue