0
我有以下功能独特的2D阵列列排列
function permutation(a){
let res = [];
for(let i=0; i<a.length; i++){
let restA = a.slice(0,i).concat(a.slice(i+1));
let rest = permutation(restA);
if(rest.length === 0){
res.push([a[i]]);
}else{
for(let j=0; j<rest.length; j++){
res.push([a[i]].concat(rest[j]));
}
}
}
return res;
}
,其生成一维数组的所有排列与像[1,2,3,4]
唯一值。
我也有充满零和一这样
[
[1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 1]
]
我需要生成该阵列的所有独特排列二维数组。我该怎么做呢?