Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 2996691

Browse files
committed
Added SRM sorting
1 parent 5789afa commit 2996691

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

app/profile/subtrack/subtrack.controller.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@
127127
return SRMService.getPastSRMs(profileVm.profile.handle, params)
128128
.then(function(data) {
129129
vm.challenges = data;
130+
// sort SRMs by points
131+
vm.challenges.sort(function(a, b) {
132+
// if both SRMs have finalPoints details
133+
var aHasFP;
134+
var bHasFP;
135+
if (
136+
(aHasFP = a.rounds[0] && a.rounds[0].userSRMDetails && a.rounds[0].userSRMDetails.finalPoints)
137+
&&
138+
(bHasFP = b.rounds[0] && b.rounds[0].userSRMDetails && b.rounds[0].userSRMDetails.finalPoints)
139+
) {
140+
// sort descending
141+
return b.rounds[0].userSRMDetails.finalPoints - a.rounds[0].userSRMDetails.finalPoints;
142+
} else if (bHasFP) {
143+
// if b has FP, b should go first
144+
return 1;
145+
} else if (aHasFP) {
146+
return -1;
147+
} else {
148+
return 0;
149+
}
150+
});
130151
vm.status.challenges = CONSTANTS.STATE_READY;
131152
})
132153
.catch(function(resp) {

0 commit comments

Comments
 (0)