const _3D = (asg)=>{
let copynub = [1];//计算后复制的次数 个位永远是1次
//总长度
const size = [...asg].reverse().reduce((p,n)=>{
p = p.length ?? p;
copynub.push(p);//重复次数等于前两位相乘
return p * n.length;
});
//按照重复次数顺序将数组展开
const newitem = copynub.reverse().map((item,index)=>{
return asg[index].map(k=>Array(item).fill(k)).flat();
});
//按总长度生成数组 将展开的数组进行列组合(竖向)
return Array(size).fill(size).map((_,k) => newitem.map(item => item[k % item.length] ));
}
console.time('计算用时By没想好');
//const res = _3D([[1,2,3],[9,0],[5,6,7,8]]);
const res = _3D([[1,2,3,4,5,6,7,8,9,0],[1,2,3,4,5,6,7,8,9,0],[1,2,3,4,5,6,7,8,9,0]]);
console.timeEnd('计算用时By没想好');
console.log("res>",res);
console.log("res.length>",res.length);
console