lua获取对比两个数组差异函数。
get_array_diff(arr, arr_other)
local function get_array_diff(arr, arr_other) assert(type(arr) == "table" and type(arr_other) == "table") local ht_other = {} for i, unit in ipairs(arr_other) do ht_other[unit] = true end local t_diff = {} local t_same = {} for i, unit in ipairs(arr) do if ht_other[unit] then table.insert(t_same, unit) else table.insert(t_diff, unit) end end return t_diff, t_same end
get_array_diff(数组1,数组2)