From 7465f854e04e4137b2e69d2c31bcea5879375fcf Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 19 Oct 2024 15:21:57 +0100 Subject: [PATCH] fix around me for top players --- projects/backend/src/service/player.service.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/projects/backend/src/service/player.service.ts b/projects/backend/src/service/player.service.ts index 2c233ea..dc14691 100644 --- a/projects/backend/src/service/player.service.ts +++ b/projects/backend/src/service/player.service.ts @@ -257,7 +257,14 @@ export class PlayerService { // Show 3 players above and 1 below the requested player const playerPosition = players.findIndex(p => p.id === player.id); const start = Math.max(0, playerPosition - 3); - const end = Math.min(players.length, playerPosition + 2); + let end = Math.min(players.length, playerPosition + 2); + + const playersLength = players.slice(start, end).length; + + // If there is less than 5 players to return, add more players to the end + if (playersLength < 5) { + end = Math.min(end + 5 - playersLength, players.length); + } return players.slice(start, end); }