From 3ef5930f4f69e978083e5b07bff44671d7e1e351 Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Fri, 24 May 2024 01:08:03 +0200 Subject: [PATCH] feat(libs): add utils.rep --- libs/utils.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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