Refactor to use the Quote objects instead of strings
This commit is contained in:
parent
4d066aed41
commit
bd98d87475
1 changed files with 9 additions and 10 deletions
|
|
@ -7,21 +7,20 @@ export default {
|
||||||
let gID = request.params.guild_id;
|
let gID = request.params.guild_id;
|
||||||
let data = db[gID].bracket;
|
let data = db[gID].bracket;
|
||||||
|
|
||||||
let winners: string[] = [];
|
let winners: quote[] = [];
|
||||||
let highest = -1;
|
let highest = -1;
|
||||||
|
|
||||||
// Iterate through all quotes that were voted for
|
// Run through all of the quotes to find the most voted for ones
|
||||||
for (var quote in data.votes) {
|
for (var quote of data.quotes) {
|
||||||
|
|
||||||
// New maximum, reset array of winners
|
// New maximum, remove all previous winners
|
||||||
if (data.votes[quote] > highest) {
|
if (quote.votes > highest) {
|
||||||
winners = [ data.quotes[quote] ];
|
winners = [ quote ];
|
||||||
highest = data.votes[quote];
|
highest = quote.votes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tied highest, add to list
|
else if (quote.votes === highest) {
|
||||||
else if (data.votes[quote] == highest) {
|
winners.push( quote );
|
||||||
winners.push( data.quotes[quote] );
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue