Fix map ranking

This commit is contained in:
Chris Blanchard 2015-10-22 10:34:40 +01:00
parent b1f7aefe46
commit 6481da2270
2 changed files with 12 additions and 1 deletions

View file

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

View file

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