Skip to content

Commit 5fe18c6

Browse files
committed
feat(page-results): move cheating users to the end
1 parent 05d95a7 commit 5fe18c6

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/app/components/results/page-results/page-results.component.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ export class PageResultsComponent implements OnInit {
4141
const scorePositions: {[score: number]: {from: number, to: number}} = {};
4242

4343
users.forEach((u) => {
44-
if (!(u.score in scoresCount)) {
45-
scores.push(u.score);
46-
scoresCount[u.score] = 0;
44+
const key = PageResultsComponent.getScoreKey(u);
45+
if (!(key in scoresCount)) {
46+
scores.push(key);
47+
scoresCount[key] = 0;
4748
}
48-
scoresCount[u.score] = scoresCount[u.score] + 1;
49+
scoresCount[key] = scoresCount[key] + 1;
4950
});
5051

5152
let previousEndingPos = 1;
@@ -57,14 +58,21 @@ export class PageResultsComponent implements OnInit {
5758
previousEndingPos = scorePositions[score].to + 1;
5859
}
5960

60-
return users.map((user) => ({
61-
...user,
62-
position:
63-
scorePositions[user.score].from === scorePositions[user.score].to ?
64-
`${scorePositions[user.score].from}.`
65-
: `${scorePositions[user.score].from}.-${scorePositions[user.score].to}.`,
66-
})).sort((a, b) => b.score - a.score);
61+
return users.map((user) => {
62+
const key = PageResultsComponent.getScoreKey(user);
63+
return {
64+
...user,
65+
position:
66+
scorePositions[key].from === scorePositions[key].to ?
67+
`${scorePositions[key].from}.`
68+
: `${scorePositions[key].from}.-${scorePositions[key].to}.`,
69+
};
70+
}).sort((a, b) => PageResultsComponent.getScoreKey(b) - PageResultsComponent.getScoreKey(a));
6771
})
6872
);
6973
}
74+
75+
private static getScoreKey(user: User): number {
76+
return !user.cheat ? user.score : -1000;
77+
}
7078
}

0 commit comments

Comments
 (0)