Skip to content

Commit b83a89a

Browse files
committed
위장문제 map으로 구현
1 parent d1c9fff commit b83a89a

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/grap3fruit/js/goorm/42578_2.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function solution(clothes) {
2+
let answer = 1;
3+
console.log(clothes);
4+
5+
const map = new Map();
6+
7+
clothes.forEach((cloth) => {
8+
if (!map.get(cloth[1])) {
9+
return map.set(cloth[1], [cloth[0]]);
10+
}
11+
12+
map.get(cloth[1]).push(cloth[0]);
13+
});
14+
15+
for (let key of map.keys()) {
16+
answer *= map.get(key).length + 1;
17+
}
18+
answer -= 1;
19+
20+
return answer;
21+
}
22+
23+
const clothes = [
24+
['yellow_hat', 'headgear'],
25+
['blue_sunglasses', 'eyewear'],
26+
['green_turban', 'headgear'],
27+
];
28+
29+
console.log(solution(clothes));

0 commit comments

Comments
 (0)