我试图通过向每个元素添加一个值,然后将这些新值添加到该数组(数组为x,y,z> sketchup)的示例来替换数组:
arr = [[2.99213, 0, 0],
[2.93025, 0.0031909, 0],
[2.86903, 0.0127298, 0],
[2.80912, 0.0285154, 0]]
在每个第一个元素中添加 2 即可获得
arr = [[4.99213, 0, 0],
[4.93025, 0.0031909, 0],
[4.86903, 0.0127298, 0],
[4.80912, 0.0285154, 0]]
最后,添加两个数组:
arr = [[2.99213, 0, 0],
[2.93025, 0.0031909, 0],
[2.86903, 0.0127298, 0],
[2.80912, 0.0285154, 0],
[4.99213, 0, 0],
[4.93025, 0.0031909, 0],
[4.86903, 0.0127298, 0],
[4.80912, 0.0285154, 0]]
答案 0 :(得分:0)
喜欢吗?
arr = [[2.99213, 0, 0], [2.93025, 0.0031909, 0], [2.86903, 0.0127298, 0], [2.80912, 0.0285154, 0]]
arr + arr.map { |k| [k[0]+2] + k[1..-1] }
# => [[2.99213, 0, 0], [2.93025, 0.0031909, 0], [2.86903, 0.0127298, 0], [2.80912, 0.0285154, 0], [4.9921299999999995, 0, 0], [4.93025, 0.0031909, 0], [4.86903, 0.0127298, 0], [4.80912, 0.0285154, 0]]