# 组合排列所有方式 怎么写啊。。

aa=["北京","天津","上海"]
bb=["一汽","三菱"]
cc=["挖掘机","收割机","推土机"]
dd=["哪家强","哪家好"]

...全文
206 11 打赏 收藏 转发到动态 举报

11 条回复

scscms太阳光 2015-06-26
• 打赏
• 举报

``````aa=["北京","天津","上海"]
bb=["一汽","三菱"]
cc=["挖掘机","收割机","推土机"]
dd=["哪家强","哪家好"]

Array.prototype.groups = function(x){
if(this.length){
var temp = [];
for(var i = 0;i < this.length;i ++){
for(var n = 0;n < x.length;n ++){
temp.push(this[i] + x[n]);
}
}
return temp.slice(0);
}else{
return x;
}
}

var str = aa.groups(bb);
str = str.groups(cc);
str = str.groups(dd);
console.log(str.join("\n"));``````
scscms太阳光 2015-06-26
• 打赏
• 举报

``````aa=["北京","天津","上海"]
bb=["一汽","三菱"]
cc=["挖掘机","收割机","推土机"]
dd=["哪家强","哪家好"]

Array.prototype.groups = function(x){
if(this.length){
var temp = [];
for(var i = 0;i < this.length;i ++){
for(var n = 0;n < x.length;n ++){
temp.push(this[i] + x[n]);
}
}
return temp.slice(0);
}else{
return x;
}
}

var str = aa.groups(bb);
str = str.groups(cc);
str = str.groups(dd);
console.log(str.join("\n"));``````

• 打赏
• 举报

``````
var arr = [
["北京","天津","上海"],
["一汽","三菱"],
["挖掘机","收割机","推土机"],
["哪家强","哪家好"]
];
function loop(i)
{
if (i>=arr.length)
return [""];
var narr = [];
var larr = loop(i+1);
for(var a=0; a<arr[i].length; a++)
for(var b=0; b<larr.length; b++)
narr.push(arr[i][a]+larr[b])
return narr;
}
document.write(loop(0).join("<br />"));

``````

• 打赏
• 举报

``````
var arr = [
["北京","天津","上海"],
["一汽","三菱"],
["挖掘机","收割机","推土机"],
["哪家强","哪家好"]
];
function loop(i)
{
if (i>=arr.length)
return [""];
var narr = [];
var larr = loop(i+1);
for(var a=0; a<arr[i].length; a++)
for(var b=0; b<larr.length; b++)
narr.push(arr[i][a]+larr[b])
return narr;
}
document.write(loop(0).join("<br />"));

``````

• 打赏
• 举报

• 打赏
• 举报

• 打赏
• 举报

• 打赏
• 举报

[quote=引用 2 楼 MoruaLee 的回复:] [quote=引用 1 楼 starfd 的回复:] 四个for循环不就行了？
``````for()
{
for()
{
for()
{
for()
{
}
}
}
}``````

• 打赏
• 举报

[quote=引用 1 楼 starfd 的回复:] 四个for循环不就行了？
``````for()
{
for()
{
for()
{
for()
{
}
}
}
}``````

• 打赏
• 举报

``````for()
{
for()
{
for()
{
for()
{
}
}
}
}``````

• 打赏
• 举报

``````for()
{
for()
{
for()
{
for()
{
}
}
}
}``````

87,942

• 近7日
• 近30日
• 至今