如何将两个数组融合为一个,如下所示:
local array1 = {2272, 2271, 2270, 2269}
local array2 = {2267, 2266, 2268, 2265, 2264, 2263, 2262, 2261}
local fusedArray = {2272, 2271, 2270, 2269, 2267, 2266, 2268, 2265, 2264, 2263, 2262, 2261}
Run Code Online (Sandbox Code Playgroud)
或者
local array1 = {2292, 2291, 2290, 2289}
local array2 = {2267, 2266, 2268, 2265, 2264, 2263, 2262, 2261}
local fusedArray = {2292, 2291, 2290, 2289, 2267, 2266, 2268, 2265, 2264, 2263, 2262, 2261}
Run Code Online (Sandbox Code Playgroud)
标准库可以帮助解决这个问题:
local function concatArray(a, b)
local result = {table.unpack(a)}
table.move(b, 1, #b, #result + 1, result)
return result
end
Run Code Online (Sandbox Code Playgroud)
请参阅文档中的table.move和。table.unpack
| 归档时间: |
|
| 查看次数: |
3004 次 |
| 最近记录: |