Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to sort an Array of numbers from High to low?

Asked by 4 years ago

If you had 3 numbers in an array/table like this:

local Scores = {2, 7, 3}

How would you sort them all from high to low or the other way around...

2 answers

Log in to vote
1
Answered by
o_fex 146
4 years ago

Hey there.

The best method out there is table.sort it's easy and simple to use and will satisfy your needs.

Here's a link to the API: https://developer.roblox.com/en-us/api-reference/lua-docs/table

Ad
Log in to vote
0
Answered by 4 years ago

If you want to be able to choose which way you can sort the numbers. Please consider using the method down below.

table.sort(table, function(a, b) return a > b end))

You can change the relational conditional operator to fit any need you want.

0
does the a and b mean the first and last number NathanTheCraziest 105 — 4y

Answer this question