-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathwhoseMove.js
25 lines (15 loc) · 922 Bytes
/
whoseMove.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
/*
Two players - "black" and "white" are playing a game. The game consists of several rounds. If a player wins in a round, he is to move again during the next round. If a player loses a round, it's the other player who moves on the next round. Given whose turn it was on the previous round and whether he won, determine whose turn it is on the next round.
Input/Output
[input] string lastPlayer/$last_player
"black" or "white" - whose move it was during the previous round.
[input] boolean win/$win
true if the player who made a move during the previous round won, false otherwise.
[output] a string
Return "white" if white is to move on the next round, and "black" otherwise.
Example
For lastPlayer = "black" and win = false, the output should be "white".
For lastPlayer = "white" and win = true, the output should be "white".
*/
//Answer//
let whoseMove=(lP, win) => win===true?lP:lP==="black"?"white":"black"