1

说我想要这两个数组

array1 = [
[1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0],
[1,0,0,0,0,0,0,0], 
[1,0,0,0,0,0,0,0],
[1,0,0,0,0,0,0,0]];

array2 = [
[1,1,1,1,1,1,1,1],
[0,0,0,0,0,0,0,1],
[0,0,0,0,0,0,0,1],
[0,0,0,0,0,0,0,1],
[0,0,0,0,0,0,0,1]];

成为这个

array3 = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]];

有没有办法做到这一点?这可能不是我想要做的最好的解决方案,但如果没有 as3 的良好经验,这是我能想到的最好的事情。

4

1 回答 1

0

试试这个代码:

    var array1:Array = [
        [1,1,1,1,1,1,1,1],
        [1,0,0,0,0,0,0,0],
        [1,0,0,0,0,0,0,0], 
        [1,0,0,0,0,0,0,0],
        [1,0,0,0,0,0,0,0]];

    var array2:Array = [
        [1,1,1,1,1,1,1,1],
        [0,0,0,0,0,0,0,1],
        [0,0,0,0,0,0,0,1],
        [0,0,0,0,0,0,0,1],
        [0,0,0,0,0,0,0,1]];     

    var array3Ref:Array = [
        [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
        [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
        [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], 
        [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
        [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]];

    var size:int = Math.max(array1.length, array2.length);
    var array3:Array = [];
    for(var i:int=0; i < size; i++)
    {
        array3[i] = array1[i].concat(array2[i]);
    }

    trace(array3.toString() == array3Ref.toString());

输出:

true

请注意,它不处理这种情况,时间array1array2长度不同。

于 2013-10-30T09:54:27.240 回答