I’m struggling with this function to get a knockout round name with just the current roundID (zero based) and the total knockout team slots. Here is the function:
export function getKnockoutRoundName(
thisRoundId: number, // Zero based
slots: number,
): string {
const totalRounds = Math.round(Math.log(slots) / Math.log(2));
const isLastRound = thisRoundId === totalRounds - 1;
if (isLastRound) {
return "Final";
}
// Doesn't work here
const teamTotal = slots / thisRoundId ??;
return teamTotal >= 16
? `Round ${teamTotal}`
: teamTotal === 8
? "Quarter"
: "Semi";
}
For example, if the knockout team slots is 256
, I want to get a knockout name like (Round of 256, Round of 32) based on the current round ID.