✨ 문제 ✨

✨ 정답 ✨
const getCombination=(howMany,howManyNumber)=>{
let combinations=[];
if (howManyNumber===1){
return howMany.map((el)=>[el]);
}
howMany.forEach((fix, i, origin)=>{
let rest=origin.slice(i+1);
let combination=getCombination(rest, howManyNumber-1);
let attach=combination.map((el)=>[fix, ...el]);
combinations.push(...attach)
})
return combinations;
}
const isOnlyOne=(relation, array)=>{
let results=[];
array.forEach((el)=>{
let set=new Set();
relation.forEach((el2)=>{
set.add(el.map((el3)=>el2[el3]).join(','));
})
if (set.size===relation.length){
results.push(el);
}
})
return results;
}
const isMinimum=(array)=>{
let results=[];
while(array.length){
results.push(array[0]);
array=array.reduce((acc, cur)=>{
let notMinimum=array[0].every(el=>cur.includes(el));
if (!notMinimum){
acc.push(cur);
}
return acc;
},[])
}
return results;
}
function solution(relation) {
var answer = 0;
let howMany=Array.from({length:relation[0].length}, (v, i)=>i);
let allCombinationsArray=[]
for (let i=0;i<howMany.length;i++){
allCombinationsArray.push(...getCombination(howMany, i+1))
}
allCombinationsArray=isOnlyOne(relation, allCombinationsArray);
allCombinationsArray=isMinimum(allCombinationsArray)
return allCombinationsArray.length;
}
🧵 참고한 정답지 🧵
https://velog.io/@euneun/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%ED%9B%84%EB%B3%B4%ED%82%A4-2019-kakao-blind-recruitment-javascript
💡💡 기억해야 할 점 💡💡