mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Renamed lume.set
-> lume.unique
This commit is contained in:
parent
758067dd33
commit
64aae8d473
@ -180,10 +180,10 @@ an error is raised,
|
||||
lume.reduce({1, 2, 3}, function(a, b) return a + b end) -- Returns 6
|
||||
```
|
||||
|
||||
#### lume.set(t)
|
||||
#### lume.unique(t)
|
||||
Returns a copy of the `t` array with all the duplicate values removed.
|
||||
```lua
|
||||
lume.set({2, 1, 2, "cat", "cat"}) -- Returns {1, 2, "cat"}
|
||||
lume.unique({2, 1, 2, "cat", "cat"}) -- Returns {1, 2, "cat"}
|
||||
```
|
||||
|
||||
#### lume.filter(t, fn [, retainkeys])
|
||||
|
2
lume.lua
2
lume.lua
@ -287,7 +287,7 @@ function lume.reduce(t, fn, first)
|
||||
end
|
||||
|
||||
|
||||
function lume.set(t)
|
||||
function lume.unique(t)
|
||||
local rtn = {}
|
||||
for k in pairs(lume.invert(t)) do
|
||||
rtn[#rtn + 1] = k
|
||||
|
@ -257,13 +257,13 @@ tests["lume.reduce"] = function()
|
||||
tester.test.error(lume.reduce, {}, add)
|
||||
end
|
||||
|
||||
-- lume.set
|
||||
tests["lume.set"] = function()
|
||||
testeq( lume.set({}), {} )
|
||||
local t = lume.set({1, 2, 3, 2, 5, 6, 6})
|
||||
-- lume.unique
|
||||
tests["lume.unique"] = function()
|
||||
testeq( lume.unique({}), {} )
|
||||
local t = lume.unique({1, 2, 3, 2, 5, 6, 6})
|
||||
table.sort(t)
|
||||
testeq( t, {1, 2, 3, 5, 6} )
|
||||
local t = lume.set({"a", "b", "c", "b", "d"})
|
||||
local t = lume.unique({"a", "b", "c", "b", "d"})
|
||||
table.sort(t)
|
||||
testeq( t, {"a", "b", "c", "d"} )
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user