How to sort a array from highest to lowest efficiently

Sorry if this sounds really noobish if you will but I basically have an array that stores numbers. I need to sort these numbers so that I could get the highest number by doing

array[#array]

And the second-lowest doing

array[#array-1]

I really don’t wanna use if statements here cause this is something that has to be done a lot in my code. But if I do need to, i’d like to know the absolute most efficient way of doing so

To sort an array, use table.sort

https://developer.roblox.com/en-us/api-reference/lua-docs/table

Does it modify the contents in the table i gave it or does it create another and has it as it’s return thing?

EDIT: it’s the former

Your efforts have produced a triangle with scanline algorithm :3
Screen Shot 2021-08-01 at 2.52.06 PM

3 Likes