Ad
Games
Fundamentals
Basic Language Features
Code
Diff
  • const whoShouldServe = (scoreLeft, scoreRight, servesCount) => {
      return Math.floor((scoreLeft + scoreRight) / servesCount) % 2 === 0 ? 'first' : 'second';
    };
    • function whoShouldServe($scoreLeft, $scoreRight, $servesCount) {
    • return floor(($scoreLeft + $scoreRight) / $servesCount) % 2 === 0 ? 'first' : 'second';
    • const whoShouldServe = (scoreLeft, scoreRight, servesCount) => {
    • return Math.floor((scoreLeft + scoreRight) / servesCount) % 2 === 0 ? 'first' : 'second';
    • };
Games
Fundamentals
Basic Language Features

This kata is about PING PONG game.
By receiveing a current score of the game and amount of serves per one player method should return a person ("first" or "second") who should do a next serve.
For example:

  • Score 0:0 and 2 serves per player - then whoShouldServe(0, 0, 2) === "first"
  • Score 4:5 and 2 serves per player - then whoShouldServe(4, 5, 2) === "second"
function whoShouldServe($scoreLeft, $scoreRight, $servesCount) {
  return floor(($scoreLeft + $scoreRight) / $servesCount) % 2 === 0 ? 'first' : 'second';
};