의상

    [JS] 의상

    map 자료형을 통해서 각 의상의 타입별로 옷이 몇개인지 세주면 된다. 어차피 경우의 수를 구하는 것이기 때문에 옷이 몇개인지만 세준 이후, 아무 옷을 안입는 경우는 빼줘야 하므로 마지막에 1을 빼준다. function solution(clothes) { const map = new Map() for (const [name,type] of clothes){ if (map.get(type)) map.set(type,map.get(type)+1) else map.set(type,1) } let ret = 1 for (const [key,val] of map){ ret *= val+1 } return ret-1 }