zoukankan      html  css  js  c++  java
  • JS使用循环获得不定维度笛卡尔积

    使用循环获得不定维度笛卡尔积:

    参考http://blog.csdn.net/buptdavid/article/details/45918647改造

    function testing()
                {
                    var d = [
                        ["a1", "a2", "a3"],
                        ["b1", "b2"],
                        ["c1", "c2", "c3", "c4"],
                        ["d1", "d2", "d3", "d4", "d5"],
                        ["e1", "e2", "e3", "e4", "e5","e6"],
                    ];
                    var total = 1;
                    for (var i = 0; i < d.length; i++)
                    {
                        total *= d[i].length;
                    }
                    var e = [];
                    var itemLoopNum = 1;
                    var loopPerItem = 1;
                    var now = 1;
                    for (var i = 0; i < d.length; i++) {
                        now *= d[i].length;
                        var index = 0;
                        var currentSize = d[i].length;
                        itemLoopNum = total / now;
                        loopPerItem = total / (itemLoopNum * currentSize);
                        var myIndex = 0;
                        for (var j = 0; j < d[i].length; j++)
                        {
                            for (var z = 0 ; z < loopPerItem; z++)
                            {
                                if (myIndex == d[i].length) {
                                    myIndex = 0;
                                }
                                for (var k = 0; k < itemLoopNum; k++)
                                {
                                    e[index] = (e[index] == null ? "" :e[index] + ",") + d[i][myIndex];
                                    index++;
                                }
                                myIndex++
                            }
                        }
                    }
                    for (var l = 0; l < e.length; l++)
                    {
                        console.log(e[l]);
                    }
                }
  • 相关阅读:
    二次冲刺站立会议五
    二次冲刺站立会议四
    二次冲刺站立会议三
    二次冲刺站立会议二
    自己常用网址导航
    Eclipse几个配置
    JVM参数和jvm.log
    JVM性能监控命令
    Linux基本信息查看命令
    Linux IO性能监控工具
  • 原文地址:https://www.cnblogs.com/enigmaxp/p/5213806.html
Copyright © 2011-2022 走看看