Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The webservice doesn't return the group's teams ordered by classification #1

Open
Eslley opened this issue Nov 21, 2022 · 0 comments
Open

Comments

@Eslley
Copy link

Eslley commented Nov 21, 2022

I've used this piece of code to sort the teams (I didn't test the goal balance and most goals scored criterias but I think it's working well) :

const compareCallBack = (team1, team2) => {
  if (team1.group_points < team2.group_points) 
    return 1

  if (team1.group_points > team2.group_points) 
    return -1

  // if the teams have the same points number, use the goal balance (goals_for - goals_against) as criteria
  if (team1.group_points === team2.group_points) {
    const saldoGTeam1 = team1.goals_for - team1.goals_against
    const saldoGTeam2 = team2.goals_for - team2.goals_against

    if (saldoGTeam1 <  saldoGTeam2)
      return 1

    if (saldoGTeam1 >  saldoGTeam2)
      return -1

    // if also draw in goal balance use most goals scored (goals_for) as criteria
    if (saldoGTeam1 === saldoGTeam2){
      if(team1.goals_for < team2.goals_for)
        return 1

        if(team1.goals_for > team2.goals_for)
        return -1
    }

  }

  return 0
}
groupsData.groups.forEach(grupo => {
  grupo.teams = grupo.teams.sort(compareCallBack)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant