• 二维数组 组合方案


    例子:

    [
      ["160514110637d4800f000005"],
      ["160514110639d4800f000009","160514110639d4800f00000a","160514110639d4800f00000b"],
      ["160514110639d4800f00000d","160514110639d4800f00000e","160514110639d4800f00000f"]
    ]

    方法:

    function doExchange(doubleArrays, fgf) {
        /// <summary>
        /// 二维数组 组合方案
        /// </summary>
        /// <param name="doubleArrays" type="type">二维数组</param>
        /// <param name="fgf" type="type">分隔符</param>
        /// <returns type=""></returns>
        if (fgf == undefined) fgf = ",";
        var len = doubleArrays.length;
        if (len >= 2) {
            var len1 = doubleArrays[0].length;
            var len2 = 0;
            try {
                len2 = doubleArrays[1].length;
            } catch (e) {
                var x = "";
            }
    
            var newlen = len1 * len2;
            var temp = new Array(newlen);
            var index = 0;
            for (var i = 0; i < len1; i++) {
                for (var j = 0; j < len2; j++) {
                    temp[index] = doubleArrays[0][i] + fgf + doubleArrays[1][j];
                    index++;
                }
            }
            var newArray = new Array(len - 1);
            for (var i = 2; i < len; i++) {
                newArray[i - 1] = doubleArrays[i];
            }
            newArray[0] = temp;
            return doExchange(newArray, fgf);
        }
        else {
            return doubleArrays[0];
        }
    }
    结果:
    [
      "160514110637d4800f000005,160514110639d4800f000009,160514110639d4800f00000d",
      "160514110637d4800f000005,160514110639d4800f000009,160514110639d4800f00000e",
      "160514110637d4800f000005,160514110639d4800f000009,160514110639d4800f00000f",
      "160514110637d4800f000005,160514110639d4800f00000a,160514110639d4800f00000d",
      "160514110637d4800f000005,160514110639d4800f00000a,160514110639d4800f00000e",
      "160514110637d4800f000005,160514110639d4800f00000a,160514110639d4800f00000f",
      "160514110637d4800f000005,160514110639d4800f00000b,160514110639d4800f00000d",
      "160514110637d4800f000005,160514110639d4800f00000b,160514110639d4800f00000e",
      "160514110637d4800f000005,160514110639d4800f00000b,160514110639d4800f00000f"
    ]
  • 相关阅读:
    一种动态部署JBoss应用的简单方法
    虚拟机启动的一个Bat文件(启动虚拟机.bat)
    Windows 设置了文件夹共享,删除默认Everyone共享,设置其他用户共享之后打不开的问题
    命令按钮怎么直接指定带参数的宏?
    bat延时
    wrapper.java.additional
    win7下vc6.0的安装
    UVA10391
    UVALive3708
    C++红黑树(类模板实现)
  • 原文地址:https://www.cnblogs.com/OleRookie/p/5498330.html
Copyright © 2020-2023  润新知