Open Sainan opened 10 months ago
Seems like a niche enough operation for filter
+ another table to handle tbh
Ehhh
table.uniques = function(t)
local seen = {}
t:filter(function(x)
if seen:contains(x) then return false end
seen:insert(x)
return true
end)
return t
end
Although might need a different name such as table.deduplicate or table.dedup so we can have table.deduplicated or table.deduped for the copying variant.
Somewhat worth noting that now this can be emulated as followed on 0.10.0:
local t = { "foo", "foo", "bar" }
print(dumpvar(t:countvalues():keys())) -- { "foo", "bar" }
Although probably still worthwhile to have its own function.
Removes duplicate values from a table