diff --git a/libs/utils.lua b/libs/utils.lua index 0ba3dc0..75b235a 100644 --- a/libs/utils.lua +++ b/libs/utils.lua @@ -92,4 +92,18 @@ utils.find = function(t, predicate) 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 \ No newline at end of file