Advertisement
CaptainSpaceCat

TableTesting

Dec 12th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.47 KB | None | 0 0
  1. local tab = {1, 2, 3, 4, 5, 6, 7, 8, 9}
  2. local tArgs = {...}
  3.  
  4. function reverseTableSection(tab, start, finish)
  5.   local temp = {}
  6.   local c = 1
  7.   for i = finish, start, -1 do
  8.     temp[c] = tab[i]
  9.     c = c + 1
  10.   end
  11.   c = 1
  12.   for i = start, finish do
  13.     tab[i] = temp[c]
  14.     c = c + 1
  15.   end
  16. end
  17.  
  18. function printTable(t)
  19.   for i = 1, #t do
  20.     write(t[i] .. " ")
  21.   end
  22.   print()
  23. end
  24.  
  25. printTable(tab)
  26. reverseTableSection(tab, tArgs[1], tArgs[2])
  27. printTable(tab)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement