1
+ //https://github.com/codeisneverodd/programmers-coding-test
2
+ //더 좋은 풀이가 존재할 수 있습니다.
3
+
4
+ //정답 1 - ssi02014
5
+ function solution ( survey , choices ) {
6
+ const points = [ 3 , 2 , 1 , 0 , 1 , 2 , 3 ] ;
7
+ const pointBoard = {
8
+ R : 0 ,
9
+ T : 0 ,
10
+ C : 0 ,
11
+ F : 0 ,
12
+ J : 0 ,
13
+ M : 0 ,
14
+ A : 0 ,
15
+ N : 0 ,
16
+ } ;
17
+ let result = "" ;
18
+
19
+ // 카테고리 별 점수 추가
20
+ for ( let i = 0 ; i < survey . length ; i ++ ) {
21
+ const categories = survey [ i ] ;
22
+
23
+ if ( choices [ i ] < 4 ) {
24
+ pointBoard [ categories [ 0 ] ] += points [ choices [ i ] - 1 ] ;
25
+ } else if ( choices [ i ] > 4 ) {
26
+ pointBoard [ categories [ 1 ] ] += points [ choices [ i ] - 1 ] ;
27
+ }
28
+ }
29
+
30
+ const pointBoardEntries = Object . entries ( pointBoard ) ;
31
+
32
+ // 지표에 맞게 결과 값 도출
33
+ for ( let i = 0 ; i < pointBoardEntries . length ; i += 2 ) {
34
+ const [ curCategory , curValue ] = pointBoardEntries [ i ] ;
35
+ const [ nextCategory , nextValue ] = pointBoardEntries [ i + 1 ] ;
36
+
37
+ if ( curValue < nextValue ) {
38
+ result += nextCategory ;
39
+ } else {
40
+ result += curCategory ;
41
+ }
42
+ }
43
+
44
+ return result ;
45
+ }
0 commit comments