There really isn’t a point in using table.remove()
, which takes O(n) time when the array is inherently unordered. In unsorted cases, a built-in unordered remove in the table
library would drastically increase performance, especially for large arrays. For example (using table.uremove()
as unordered remove):
local largeTable = table.create(someLargeNumber, true)
table.remove(largeTable, 1) --> requires [someLargeNumber - 1] operations
local anotherLargeTable = table.create(someLargeNumber, true)
table.uremove(anotherLargeTable, 1) --> requires 1 operation
Currently, developers are forced to write their own function to do this, which could be avoided if a built-in option were provided:
local function uremove(t: {any}, index: number)
t[index], t[#t] = t[#t], nil
end
There are many instances where table.uremove()
could replace table.remove()
, so it’s not a niche use case.