美文网首页
Lua练习13-table中元素去重

Lua练习13-table中元素去重

作者: GameObjectLgy | 来源:发表于2020-10-19 15:25 被阅读0次
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

相关文章

网友评论

      本文标题:Lua练习13-table中元素去重

      本文链接:https://www.haomeiwen.com/subject/hblbyktx.html