Currently I'm trying to make a table for holding values. But when I use table.sort it just makes the highest go to the end(which I understand that's the intention with it).. but is there a way to make it sort from highest to lowest?
✓ ANSWER ACCEPTED
Is it possible to sort a table from highest to lowest instead of lowest to highest?
1 answer
✓ Accepted answer
Yes, and believe it or not its using the same function table.sort
If you dont define a comparator in the sort function it will always default to less than, which sorts from lowest to highest, to add a comparator just add a function in the second argument that returns if the value is higher
local table1 = {10,34,1,23}
table.sort(table1,function(a,b)
return a>b
end)
for i,v in pairs(table1) do
print(v)
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Alright thanks! I didn't realize that :P
No problem bro, have fun coding!