table.remove() calculates the length of the table to determine
how much to move.
The length of a table in Lua is ambiguous when nil elements are
present. The result may change, depending on the Lua version, Lua
implementation and even runtime characteristics.
This is all spelled out in the Lua manual (for various versions),
e.g. here: https://www.lua.org/manual/5.4/manual.html#3.4.7
In other words: #({ nil, 1 }) can return either 0 or 2. Avoid nil
in arrays, if you want predictable results.
--Mike