Please note this operation has O(log(N)) complexity. Try not to put nil in arrays. The length operator # will be confused and standard table functions like table.sort() will complain bitterly.