-
Notifications
You must be signed in to change notification settings - Fork 0
/
Challengs-35.js
28 lines (17 loc) · 1 KB
/
Challengs-35.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
// Task
// 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".
//solution
function whoseMove(lastPlayer, win) {
return win ? lastPlayer : lastPlayer === "black" ? "white" : "black";
}
whoseMove("black", false);