-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrock-paper-scissors.js
More file actions
33 lines (31 loc) ยท 975 Bytes
/
rock-paper-scissors.js
File metadata and controls
33 lines (31 loc) ยท 975 Bytes
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
/**
* @desc problem : ๊ฐ์๋ฐ์๋ณด
* @desc site : Olympiad
* @desc level: 2
* @desc problem : ์์์ ๊ท์น์ ์ด์ฉํ ํ์ด
*/
/**
* Solution
* @desc : ๊ฐ์ : 1, ๋ฐ์ : 2, ๋ณด : 3
* @param {array} playerA: A์ ๊ฐ์๋ฐ์๋ณด ๊ธฐ๋ก
* @param {array} playerB : B์ ๊ฐ์๋ฐ์๋ณด ๊ธฐ๋ก
*/
function solution(playerA, playerB) {
const result = [];
for (let index = 0; index < playerA.length; index++) {
const choiceOfA = playerA[index];
const choiceOfB = playerB[index];
if (choiceOfA - choiceOfB === -2) {
result.push('A');
} else if (choiceOfA - choiceOfB === 2) {
result.push('B');
} else if (choiceOfA === choiceOfB) {
result.push('D');
} else {
choiceOfA > choiceOfB ? result.push('A') : result.push('B');
}
}
return result;
}
const answer = solution([2, 3, 3, 1, 3], [1, 1, 2, 2, 3]);
console.log(answer); //A, B, A, B, D