let arr = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
    [10, 11, 12],
];
 
function cartesianProductOf() {
    return Array.prototype.reduce.call(arguments,       function(a, b) {
        var ret = [];
        a.forEach(function(a) {
            b.forEach(function(b) {
                ret.push(a.concat([b]));
            });
        });
        return ret;
    }, [[]]);
}
 
let allArr =cartesianProductOf(...arr )
console.log(allArr)

 

 

此算法类似笛卡尔积

 

 

 

转: https://www.cnblogs.com/hpx2020/p/10723192.html

 

相关文章:

  • 2022-12-23
  • 2022-01-04
  • 2022-12-23
  • 2021-10-08
  • 2022-01-11
  • 2021-12-29
  • 2021-10-02
  • 2021-11-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2021-12-06
  • 2021-07-08
  • 2022-01-26
相关资源
相似解决方案