From bd98d8747511d46f0fb832fb83ce608e1dfab1cc Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sun, 29 Aug 2021 15:16:05 -0600 Subject: [PATCH] Refactor to use the Quote objects instead of strings --- src/endpoints/management/winners.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/endpoints/management/winners.ts b/src/endpoints/management/winners.ts index d41b672..fd30f73 100644 --- a/src/endpoints/management/winners.ts +++ b/src/endpoints/management/winners.ts @@ -7,21 +7,20 @@ export default { let gID = request.params.guild_id; let data = db[gID].bracket; - let winners: string[] = []; + let winners: quote[] = []; let highest = -1; - // Iterate through all quotes that were voted for - for (var quote in data.votes) { + // Run through all of the quotes to find the most voted for ones + for (var quote of data.quotes) { - // New maximum, reset array of winners - if (data.votes[quote] > highest) { - winners = [ data.quotes[quote] ]; - highest = data.votes[quote]; + // New maximum, remove all previous winners + if (quote.votes > highest) { + winners = [ quote ]; + highest = quote.votes; } - // Tied highest, add to list - else if (data.votes[quote] == highest) { - winners.push( data.quotes[quote] ); + else if (quote.votes === highest) { + winners.push( quote ); }; };