/*
조합 찾기

a라는 배열이 있을때 [1,2,3,4]
b만큼의 갯수를 뽑아서 반환해준다.

*/
//a=[]//조합이 될 배열
//b=n//조합될 수
//save=[]//지금까지 쌓은것
//select=[0]*a길이 //select는 중복 체크용
function getComb(a,b,save,select){
    if(b===1){//b가 1이될때 최종 반환한다.
        let result = [];
        for(let i=0;i<a.length;i++){
            if(select[i]===0){
                result.push([...save,a[i]])
            }
        }
        return result;
    }else{
        let result = [];
        for(let i=0;i<a.length;i++){
            if(select[i]===0){

                let tmpSelect = select.slice();
                let tmpSave = save.slice();
                tmpSelect[i]=1;
                tmpSave.push(a[i])
                
                result.push(...getComb(a,b-1,tmpSave,tmpSelect))//b를 1씩 줄인다.
            }
        }
        return result;
    }
}