문제:
https://programmers.co.kr/learn/courses/30/lessons/42883?language=javascript
카테고리 : 해시
주어진 의상 정보에서 서로 다른 옷의 조합의 수를 세는 문제이다.
경우의 수로 생각하면 단순한 문제이다.
옷의 종류별로 동시에 발생할 수 있는 옷의 모든 경우의수를 구하면 된다.
function solution(clothes) {
var answer =0;
let lookup = {};
for (let [clothe, kind] of clothes) {
if (!lookup[kind]) lookup[kind] = [];
lookup[kind].push(clothe);
}
let total = 1;
for (let kind of Object.keys(lookup)) {
total *= lookup[kind].length + 1;
}
answer = total - 1;
return answer;
}