js实现超简单sku组合算法(不同属性的排列组合)


 

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM