diff --git a/sonic-radiance.love/birb/utils/table.lua b/sonic-radiance.love/birb/utils/table.lua index 2a959eb..0c3b0d2 100644 --- a/sonic-radiance.love/birb/utils/table.lua +++ b/sonic-radiance.love/birb/utils/table.lua @@ -152,4 +152,25 @@ function Table.parse(table, structure, nullableNbr) return parsedTable end +function Table.remove(table, funcDelete) + -- Code from https://stackoverflow.com/questions/12394841/safely-remove-items-from-an-array-table-while-iterating + local j, n = 1, #table; + + for i=1,n do + if (not funcDelete(table[i], i, j)) then + -- Move i's kept value to j's position, if it's not already there. + if (i ~= j) then + table[j] = table[i]; + table[i] = nil; + end + -- Increment position of where we'll place the next kept value. + j = j + 1; + else + table[i] = nil; + end + end + + return table; +end + return Table