mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-25 23:24: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}
|
-- amount -1: {1, 2, 3, 4} -> {4, 1, 2, 3}
|
||||||
function tablex.rotate(t, amount)
|
function tablex.rotate(t, amount)
|
||||||
if #t > 1 then
|
if #t > 1 then
|
||||||
while amount > 0 do
|
while amount >= 1 do
|
||||||
tablex.push(t, tablex.shift(t))
|
tablex.push(t, tablex.shift(t))
|
||||||
amount = amount - 1
|
amount = amount - 1
|
||||||
end
|
end
|
||||||
while amount < 0 do
|
while amount <= -1 do
|
||||||
tablex.unshift(t, tablex.pop(t))
|
tablex.unshift(t, tablex.pop(t))
|
||||||
amount = amount + 1
|
amount = amount + 1
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user