Skip to content

Instantly share code, notes, and snippets.

@anthonyec
Last active January 7, 2019 13:42
Show Gist options
  • Save anthonyec/bd495660a99d56d3417b07dfb2c3954e to your computer and use it in GitHub Desktop.
Save anthonyec/bd495660a99d56d3417b07dfb2c3954e to your computer and use it in GitHub Desktop.
Ping Pong who is serving
function getPlayerServing(totalScore = 0, numberOfServesEach = 2, numberOfPlayers = 2) {
return Math.floor((totalScore / numberOfServesEach)) % numberOfPlayers;
}
// Singles
// Player 1 = 0, Player 2 = 1
getPlayerServing(11);
// Doubles
// Player 1 = 0, Player 2 = 1, Player 3 = 2, Player 4 = 3
getPlayerServing(15, 5, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment