Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b0fa059

Browse files
jaewon1676prove-ability
authored andcommitted
Update 위장.js
1 parent a631752 commit b0fa059

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎level-2/위장.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,26 @@ function solution(clothes) {
4444

4545
return answer - 1;
4646
}
47+
48+
//정답 4 - jaewon1676
49+
function solution(clothes) {
50+
var answer = 1;
51+
var obj={};
52+
for(var i=0;i<clothes.length;i++){
53+
obj[clothes[i][1]]=(obj[clothes[i][1]] || 1) + 1;
54+
console.log(obj)
55+
}
56+
57+
for(var key in obj){
58+
answer *= obj[key];
59+
console.log(answer)
60+
}
61+
62+
return answer-1;
63+
}
64+
/* 풀이과정
65+
1. 빈 객체(obj)생성
66+
2. obj에 해당 키가 없으면 값을 1(옷을 입지 않은 경우)로 지정하고 1(옷의 개수)을 더해줌.
67+
3. obj에 해당 키가 있으면 해당 키의 값을 불러오고 1을 더해줌.
68+
4. for in 구문으로 obj의 키를 반복하여 불러오고 해당 값을 answer에 곱해줌
69+
5. 최소한 1가지 이상의 옷을 입기 떄문에 옷을 입지 않은 경우 -1로 제외. */

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /