generated from Lidemy/mentor-program-5th
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw5.js
41 lines (34 loc) · 823 Bytes
/
hw5.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
41
/* eslint-disable no-unused-vars */
function solve(lines) {
for (let i = 1; i < lines.length; i++) {
const [a, b, c] = lines[i].split(' ')
console.log(finalCompare(a, b, Number(c)))
}
}
function finalCompare(a, b, c) {
let result = ''
switch (c) {
case 1:
result = (a.length === b.length) ? numberCompare(a, b, c) : a.length > b.length ? 'A' : 'B'
break
case -1:
result = (a.length === b.length) ? numberCompare(a, b, c) : a.length > b.length ? 'B' : 'A'
break
}
return result
}
function numberCompare(a, b, c) {
if (a === b) return 'DRAW'
let result = ''
switch (c) {
case 1:
result = (a > b) ? 'A' : 'B'
break
case -1:
result = (a > b) ? 'B' : 'A'
break
default:
result = (a > b) ? 'A' : 'B'
}
return result
}