Minetest-WorldEditAdditions/worldeditadditions/utils/tables/table_unique.lua
Starbeamrainbowlabs db7b20d485
Refactor table functions into subtable of wea
Also, you can return a value from dofile()!!!!

This changes everything.
2021-06-28 00:56:29 +01:00

22 lines
549 B
Lua

--- Builds a new table with the elements of the given table appearing at most once.
-- @param tbl table The table of values to make unique.
-- @returns table A new table containing the values of the given table appearing at most once.
local function table_unique(tbl)
local newtbl = {}
for i,value in ipairs(tbl) do
local seen = false
for j,seenvalue in ipairs(newtbl) do
if value == seenvalue then
seen = true
break
end
end
if not seen then
table.insert(newtbl, value)
end
end
return newtbl
end
return table_unique