<html>

	<head>
<title>二维数组排列组合</title>
</head> <body>
<div id="showDiv"></div>
</body> <script type="text/javascript">
var arrays = [
[
'1-1-雨尘', '1-2-芸芸', '1-3-简一', '1-4-乐乐'
]
, [
'2-5-小明', '2-6-花花', '2-7-数数'
]
, [
'3-8-静静', '3-9-点点', '3-10-hapday', '3-11-欢欢', '3-12-yuchen'
]
];
// debugger; /**
* 递归法排列组合二维数组
*/
function doExchange(doubleArrays){
var len=doubleArrays.length; if (len >= 2) {
var len1 = doubleArrays[0].length;
var len2 = doubleArrays[1].length;
var newlen = len1 * len2;
var temp = new Array(newlen);
var rowIndex=0; for(var index = 0; index < len1; index++){
for(var cursor = 0; cursor < len2; cursor++){
temp[rowIndex] = doubleArrays[0][index] + '#' + doubleArrays[1][cursor]; rowIndex++;
}
} var newArray = new Array(len-1); for (var index = 2; index < len; index++) {
newArray[index - 1] = doubleArrays[index];
} newArray[0] = temp; var result = doExchange(newArray);
console.log(result);
return result;
} else {
var result = doubleArrays[0];
console.log('只有一个内层数组:\n' + result + '\n');
console.log('===================================');
return result;
}
} var ret = doExchange(arrays); window.document.getElementById('showDiv').innerHTML += '共有 ' + ret.length + ' 种组合。<br /><br />'; for (var index = 0; index < ret.length; index++) {
var row = ret[index];
var rows = row.split('#');
// debugger;
for (var cursor = 0; cursor < rows.length; cursor++) {
window.document.getElementById('showDiv').innerHTML += rows[cursor] + '        ';
}
window.document.getElementById('showDiv').innerHTML += '<br />';
} </script> </html>

  

最新文章

  1. AlloyTouch全屏滚动插件发布--30秒搞定顺滑H5页
  2. 实践:Backbone作前端,Django+Tastypie作后端的简单Web在线聊天室
  3. 学习总结——Selenium元素定位
  4. Delphi 2010 Can&#39;t load package C:\Programme\Afalinasoft\Add-in Express 2\d5units\adxwizardd5.bpl.
  5. 网络编程中获取域名和id的方法
  6. ros与下位机通信常用的c++ boost串口应用
  7. 《OD大数据实战》Hive入门实例
  8. Axzue注册码
  9. 设计模式24---设计模式之职责链模式(Chain of Responsibility)(行为型)
  10. Ztree中simpleData是怎么转换成标准ztree数组对象的
  11. popen()函数详解
  12. ExtJS4.1自带API打不开的问题解决
  13. Spring学习笔记①
  14. github上传项目
  15. 游戏人工智能编程案例精粹(修订版) (Mat Buckland 著)
  16. Linux JDK Tomcat Nginx MariaDB 安装,Nginx 多域名转发配置
  17. Windows下命令行怎样登录MySQL
  18. CentOS安装mysql源码包
  19. linux下安装mysql等信息
  20. 结合 Redis 实现同步锁

热门文章

  1. dbproxy-id生成器
  2. 1.jQuery入口函数
  3. python函数超时情况应对总结
  4. V1-bug Alpha阶段发布说明
  5. spring框架中的aop技术
  6. 1、The Fctory Pattern(工厂模式:解决对象创建问题)
  7. RabbitMQ---初识
  8. Python - 购物车代码 (账户登陆,用户个人清单存取,重要信息高亮显示)
  9. jacvascript 保留小数点
  10. 那些H5用到的技术(2)——音频和视频播放