Skip to content

Commit

Permalink
Fix issue with leaderboard being displayed wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
jggoebel committed May 31, 2024
1 parent 5e3a249 commit feb7454
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/app/services/score.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,12 @@ export class ScoreService {
private findLocalScores(leaderboard: Leaderboard, newScore: Score) {
// Create a deep copy of the scores and add the new score for sorting and placement
const scores = [...leaderboard.scores];
scores.push(newScore);

// Sort the scores array by score in descending order
scores.sort((a, b) => b.score - a.score);

// Determine the placement (number of scores greater than the current score)
const placement =
scores.filter((s) => s.score >= newScore.score).length - 1;
const placement = scores.filter((s) => s.score >= newScore.score).length;

// Create an array to hold local scores
const localScores: Score[] = [];
Expand All @@ -165,7 +163,7 @@ export class ScoreService {
}

for (
let i = placement + 1;
let i = placement;
i < scores.length && localScores.length < 4;
i++
) {
Expand Down

0 comments on commit feb7454

Please sign in to comment.