brackt/app/lib/standings-display.ts

21 lines
813 B
TypeScript
Raw Normal View History

/**
* Returns the display rank for a team on the league home standings preview.
*
* Rules:
* - If the team has a standing, return its numeric rank.
* - If the team has no standing, it is tied at the position just after all
* ranked teams. For example, if 3 teams have standings the unranked teams
* show "T4". If no team has standings yet (scores haven't been calculated)
* every team is genuinely tied at zero and shows "T1".
*
* @param standing - The team's standing record, or undefined if none exists.
* @param standingsCount - Total number of teams that have a standing record.
*/
export function getDisplayRank(
standing: { currentRank: number } | undefined,
standingsCount: number
): number | string {
if (standing) return standing.currentRank;
return `T${standingsCount + 1}`;
}