1 export const compareResult = round => (a, b) => {
2 const a_result = findResult(a, round);
3 const b_result = findResult(b, round);
4 const a_time = a_result && !a_result.forfeit ? a_result.time : 0;
5 const b_time = b_result && !b_result.forfeit ? b_result.time : 0;
8 if (a_time < b_time) return -1;
9 if (b_time < a_time) return 1;
17 const a_forfeit = a_result && a_result.forfeit;
18 const b_forfeit = b_result && b_result.forfeit;
31 export const compareUsername = (a, b) => {
32 const a_name = a && a.user && a.user.username ? a.user.username : '';
33 const b_name = b && b.user && b.user.username ? b.user.username : '';
34 return a_name.localeCompare(b_name);
37 export const findResult = (participant, round) => {
38 if (!participant || !participant.user_id) return null;
39 if (!round || !round.results || !round.results.length) return null;
40 return round.results.find(result => result.user_id === participant.user_id);
43 export const sortByResult = (participants, round) => {
44 if (!participants || !participants.length) return participants;
45 if (!round || !round.results || !round.results.length) return participants;
46 return participants.sort(compareResult(round));