SOURCE

// 递归实现个全排

function quanSort(index =0,arr =[],resArr=[],preArr=[]){
    //index是数组当前下标,arr是原数组的引用,resArr是返回的数组,preArr是临时数组
    if(index!=arr.length){
        arr[index].forEach(item=>{
            let preList = [...preArr,item];
            quanSort(index+1,arr,resArr,preList)
        })
    }else{
        resArr.push(preArr)
    }
    return resArr
}

let params = [[1,2,3],['a','b','c'],["你","我","他"]]
let r1 = quanSort(0,params)
console.log(r1)
console 命令行工具 X clear

                    
>
console