From 54ab1570b1e37b349d0996bdd204fb2116116536 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Mon, 17 Jun 2019 12:50:26 +0200 Subject: [PATCH] Sort teams more explicitly and in the right order --- app/services/group_stage_service.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/services/group_stage_service.rb b/app/services/group_stage_service.rb index c8f7181..5b9f1ce 100644 --- a/app/services/group_stage_service.rb +++ b/app/services/group_stage_service.rb @@ -61,10 +61,13 @@ class GroupStageService # @param group Group the group to get the teams from # @return [Array] of teams def teams_sorted_by_group_scores(group) - group.teams.sort_by do |t| - [group.group_scores.find_by(team: t).group_points, - group.group_scores.find_by(team: t).difference_in_points, - group.group_scores.find_by(team: t).scored_points] + group.teams.sort do |a, b| + [group.group_scores.find_by(team: b).group_points, + group.group_scores.find_by(team: b).difference_in_points, + group.group_scores.find_by(team: b).scored_points] <=> + [group.group_scores.find_by(team: a).group_points, + group.group_scores.find_by(team: a).difference_in_points, + group.group_scores.find_by(team: a).scored_points] end end