๋ฌธ์ ๐ฝ
https://school.programmers.co.kr/learn/courses/30/lessons/42578
๋ค๋ฅธ์ฌ๋ ํ์ด ๐ฝ
function solution(clothes) {
let answer = 1;
const obj = {};
for(let arr of clothes) {
obj[arr[1]] = (obj[arr[1]] || 0) + 1;
}
for(let key in obj) {
answer *= (obj[key]+1);
}
return answer - 1;
}
๋ดํ์ด๐ฝ
1. ์คํจ โญ
function solution(clothes) {
var answer = 1;
let obj = {}
clothes.forEach((value)=>{
if(obj[value[1]]){
obj[value[1]].push(value[0])
}else{
obj[value[1]]=[value[0]]
}
})
let keyArray = Object.keys(obj)
keyArray.forEach((key)=>{
answer = answer * (obj[key].length+1)
})
return answer-1;
}
๋๋์ ๐ฝ
for in <- ๊ฐ์ฒด์ key์ ์ ๋ธ ๊ฐ๋ฅ
for of <- ES6์ ๋ฑ์ฅ ๊ฐ์ฒด์ ๊ฐ์ ์ ๊ทผ ๊ฐ๋ฅ
forEach <- Array์์๋ง ์ฌ์ฉ ๊ฐ๋ฅ (ES6๋ถํฐ๋ Map, Set์์๋ ์ฌ์ฉ ๊ฐ๋ฅ.. )ํ๋ฉฐ ์์์ , index์๋ ์ ๊ทผ ๊ฐ๋ฅ