8000 The webservice doesn't return the group's teams ordered by classification · Issue #1 · cyrusDev1/qatar-worldcup · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
The webservice doesn't return the group's teams ordered by classification #1
Open
@Eslley

Description

@Eslley

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)
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0