本文实例讲述了javascript笛卡尔积超简单实现算法。分享给大家供大家参考,具体如下:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>js笛卡尔积算法</title> </head> <body> <script> 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; }, [[]]); } console.log(cartesianproductof(['1','3'],['a','b'])) </script> </body> </html>
使用在线html/css/javascript代码运行工具:,测试结果如下:
更多关于javascript相关内容感兴趣的读者可查看本站专题:《javascript数学运算用法总结》、《javascript数据结构与算法技巧总结》、《javascript数组操作技巧总结》、《javascript事件相关操作与技巧大全》、《javascript操作dom技巧总结》及《javascript字符与字符串操作技巧总结》
希望本文所述对大家javascript程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
Parallels Desktop v15.1.4-47270 商业版下载 Mac安装Windows首选虚拟机
关于LPC824Lite开发板下载程序时提示"Invalid ROM Table"
MySQL 5.7 关于 JSON 类型的子集Key/Value获取方法分享
javascript从入门到跑路-----小文的js学习笔记(19)------- js的垃圾回收机制
网友评论