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.time : 0;
5 const b_time = b_result ? b_result.time : 0;
8 if (a_time < b_time) return -1;
9 if (b_time < a_time) return 1;
20 export const compareUsername = (a, b) => {
21 const a_name = a && a.user && a.user.username ? a.user.username : '';
22 const b_name = b && b.user && b.user.username ? b.user.username : '';
23 return a_name.localeCompare(b_name);
26 export const findResult = (participant, round) => {
27 if (!participant || !participant.user_id) return null;
28 if (!round || !round.results || !round.results.length) return null;
29 return round.results.find(result => result.user_id === participant.user_id);
32 export const sortByResult = (participants, round) => {
33 if (!participants || !participants.length) return participants;
34 if (!round || !round.results || !round.results.length) return participants;
35 return participants.sort(compareResult(round));