brasileirao
Version:
<p align="center"> <a href="https://github.com/godrix/brasileirao/actions"> <img src="https://img.shields.io/github/actions/workflow/status/godrix/brasileirao/publish.yml"/> </a> <a href="https://github.com/godrix/brasileirao"> <img src="htt
22 lines (17 loc) • 471 B
text/typescript
interface WinPercentageOptions {
pointsPerWin?: number;
accuracy?: boolean;
}
export const calculateWinPercentage = (
points: number,
played: number,
options?: WinPercentageOptions
): number | string => {
const { pointsPerWin = 3, accuracy = false } = options ?? {}
const possiblePoints = played * pointsPerWin
const percentage = (points / possiblePoints) * 100
if (accuracy) {
return percentage.toFixed(2)
}
return Math.floor(percentage)
}