Lua练习13-table中元素去重

2020-10-19  本文已影响0人  GameObjectLgy
TableA = {8,9,1,9,8,7,5,6,3,2,1,2,3,8,9,6,4}

function TableUnique(t)
    local check = {} 
    local n = {}
    for key, value in pairs(t) do
        if not check[value] then
            n[key] = value
            check[value] = value
        end
    end
    return n
end

for key, value in pairs(TableUnique(TableA)) do
    print("value is:"..value)
end
上一篇下一篇

猜你喜欢

热点阅读