forked from eltotoloco/js-katas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tennis-score.js
40 lines (26 loc) · 1.53 KB
/
tennis-score.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Create a function `getScore` which returns the string of the current scores of a tennis game, from a number array where each value represents the player that scored.
* [1, 1, 2, 2, 1] : serving player (1) scored twice, then the receiving player (2) scored twice, and finally the serving player (1) scored once.
The expected result is "40-30".
Game rules :
The score on the left represents the serving player (1), the score on the right represents the receiving player (2).
Scores from zero to three points are described as "love", "15", "30", and "40", respectively.
If at least three points have been scored by each player, the score is not called out as "40–40", but rather as "deuce".
If at least three points have been scored by each side and a player has one more point than his opponent, the score of the game can be called "ad in" when the serving player (1) is ahead, and "ad out" when the receiving player (2) is ahead.
Example:
* points : [1, 1, 1], result : "40-love"
* points : [2, 1, 2, 2], result : "15-40"
* points : [1, 2, 1, 2, 1, 2], result : "deuce"
* points : [1, 1, 1, 2, 2, 2, 1], result : "ad in"
If the argument is null or not an array, throw a TypeError.
If a value of the argument is null or not a number, throw a TypeError.
If a value of the argument is not 1 or 2, throw a RangeError.
Add you own tests.
*/
// TODO add your code here
// Begin of tests
const assert = require("assert");
assert.strictEqual(typeof getScore, "function");
assert.strictEqual(getScore.length, 1);
// TODO add your tests:
// End of tests