Added lume.clear() and tests

This commit is contained in:
rxi 2015-02-07 22:51:28 +00:00
parent 14b9ee0ca2
commit fa85f83d70
2 changed files with 18 additions and 0 deletions

View File

@ -175,6 +175,14 @@ function lume.remove(t, x)
end
function lume.clear(t)
local iter = getiter(t)
for k, v in iter(t) do
t[k] = nil
end
end
function lume.shuffle(t)
local rtn = {}
for i = 1, #t do

View File

@ -129,6 +129,16 @@ tests["lume.remove"] = function()
local m = { a = 1, b = 2, c = 3 }
end
-- lume.clear
tests["lume.clear"] = function()
local t = { 1, 2, 3 }
lume.clear(t)
testeq(t, {})
local m = { a = 1, b = 2, c = 3 }
lume.clear(m)
testeq(m, {})
end
-- lume.shuffle
tests["lume.shuffle"] = function()
local t = {1, 2, 3, 4, 5}