diff --git a/README.md b/README.md index 16a6110..3c8eba4 100644 --- a/README.md +++ b/README.md @@ -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]) diff --git a/lume.lua b/lume.lua index 3d2a800..9958f85 100644 --- a/lume.lua +++ b/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 diff --git a/test/test.lua b/test/test.lua index fd4b6f2..e81d2c5 100644 --- a/test/test.lua +++ b/test/test.lua @@ -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