If I gathered numbers within a table or without and need them greatest to least without using table.sort().
Greatest to Least without table.sort()?
1 answer
If you need a list sorted, it doesn't make sense to reinvent what's already been given to you. Sorting is moderately difficult to get right, and in any case you will need to implement the comparison function you'd be giving to table.sort in the first place.
If you wanted to sort a list of these items by their .rap, you could use something like this:
function descendingRAP(a, b)
return a.rap > b.rap
end
table.sort(Items, descendingRAP)
Another option, instead of using table.sort, you can just insert the item into the proper place:
function add(element)
for i = 1, #list do
if element < list[i] then
table.insert(list, i, element)
return
end
end
table.insert(list, element)
end
where element < list[i] could be replaced by any less(element, list[i]), where less is the function you would pass as the second parameter to table.sort.
1 comment
I asked you this exact question a while back, and I was about to give the answer you gave me but you beat me to the chase xD
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
You could implement it yourself. But why can't you use table.sort?
My table uses multiple values within an value.
Why can't you use table.sort for that...?
Trying to sort 'table.insert(Items, {Item.id, Item.name, Item.rap, #Item.userAssetId})' is tricky. "table.sort(Items, function(a, b) return a > b end)"