Jump to content

Table Sorting


Recommended Posts

Hello Community. I need a bit of help with sorting some numbers inside a table starting from the lowest value to the highest.

The numbers inserted into the table will be math.random but for this exercise we're using numbers: 2, 4, 6, 8 and 10.

My question is, with the following example down below is there a simple way to make them output in the order of: 2, 4, 6, 8, 10 instead of: 10, 8, 2, 6, 4 ?

numTable = {}

-- insert
table.insert(numTable, 10)
table.insert(numTable, 8)
table.insert(numTable, 2)
table.insert(numTable, 6)
table.insert(numTable, 4)

-- sort

-- output
outputChatBox(tostring(numTable[1])..", "..tostring(numTable[2])..", "..tostring(numTable[3])..", "..tostring(numTable[4])..", "..tostring(numTable[5]))

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...