Create unordered-table-remove.md

This commit is contained in:
VegetationBush 2025-04-23 14:26:06 -04:00 committed by GitHub
parent f01741502c
commit b84301d7bf
Signed by: DevComp
GPG key ID: B5690EEEBB952194

27
unordered-table-remove.md Normal file
View file

@ -0,0 +1,27 @@
# Unordered `table.remove()`
## Summary
Add an unordered remove method to the table library.
## Motivation
For arrays that are known to be unsorted, using `table.remove()` to remove indicies is unperformant, as `table.remove()` takes O(n) time to complete. This is a gross use of resources, especially if this behavior is not required by the user. Thus, it's logical to conclude that an analogous method that performs an *unordered remove* would be the clear next step.
## Design
The naming of the new method is proposed as `uremove`. However, for clarity reasons, this may not be the best name choice as `uremove` types very similar to `remove`. The implementation of the method could be as such:
```lua
function table.uremove(t: {any}, index: number)
t[index], t[#t] = t[#t], nil
end
```
Valid argument checking is optional.
## Drawbacks
Possibly none, apart from an extra method in the table library.
## Alternatives
Users can define the function themselves.