mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 00:53:00 +00:00
wea.table_unique(): Add API function
This commit is contained in:
parent
8eb9a8ed0f
commit
c7c6a848dc
1 changed files with 19 additions and 0 deletions
|
@ -79,3 +79,22 @@ function worldeditadditions.table_map(tbl, func)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- 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.
|
||||||
|
function worldeditadditions.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
|
||||||
|
|
Loading…
Reference in a new issue