mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 06:04:35 +00:00
changed tablex.rotate loop bounds to be more defensive about fractional arguments being passed
This commit is contained in:
parent
0a02d7a2da
commit
27b548bb25
@ -66,11 +66,11 @@ end
|
||||
-- amount -1: {1, 2, 3, 4} -> {4, 1, 2, 3}
|
||||
function tablex.rotate(t, amount)
|
||||
if #t > 1 then
|
||||
while amount > 0 do
|
||||
while amount >= 1 do
|
||||
tablex.push(t, tablex.shift(t))
|
||||
amount = amount - 1
|
||||
end
|
||||
while amount < 0 do
|
||||
while amount <= -1 do
|
||||
tablex.unshift(t, tablex.pop(t))
|
||||
amount = amount + 1
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user