feat(libs): add utils.rep
This commit is contained in:
parent
f9fb8e26df
commit
3ef5930f4f
@ -92,4 +92,18 @@ utils.find = function(t, predicate)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- repeat n times the given element x in a new table
|
||||||
|
utils.rep = function(x, n)
|
||||||
|
if n < 1 then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = {}
|
||||||
|
for i=1, n, 1 do
|
||||||
|
result[i] = x
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
return utils
|
return utils
|
||||||
Loading…
Reference in New Issue
Block a user