How to list integers from least to greatest?

I’ve seen some other DevForum posts about how to do this, but it doesn’t really apply to what I’m trying to achieve here.

I’m trying to list integers in a table from greatest to least. For example, let’s say this is the table:

local Table = {5,2,8,4,9,3}

When all’s said and done, I want it to return this:

{9,8,5,4,3,2}

Any help will be appreciated. Thanks in advance!

table.sort(Table)
I believe they use quick sort for that, but you could use stuff such as insertion sort since your entry is small. It’d be faster but to be fair it wouldnt really matter since it so small lol

Sorry, it’s possible I was a little confused by your instructions, could you please specify?

Just call table.sort(Table) and then it should be sorted

It returns nothing when I print it.

local Table = {9,4,2,10,3}
print(table.sort(Table))

image

Worth noting that by default, table.sort sorts from least to greatest (little confusion in the title from the @OP). So you would actually need to provide a callback function for sorting:

table.sort(Table, function(entryA, entryB)
    return entryA > entryB
end)

Also @OP, table.sort doesn’t create a new table nor does it return one - it will affect the table itself since tables are passed by reference

Ah, I see. I am fairly new to these pesky table functions and I haven’t really used the in the past before, thanks for your help!