table.SortByKey
From Garry's Mod
Contents |
Description
Returns a list of keys sorted based on values of those keys.
For normal sorting see table.sort.
Arguments
table tab
Table to sort. All values of this table must be of same type.
Arguments
boolean descending=false
Should the order be descending?
Returns
A table of keys sorted by values from supplied table.
Examples
Example
Example usage of the function.
local t = {} t['h'] = 2 -- Lowest value t['a'] = 150 -- Highest value t['x'] = 30 PrintTable( table.SortByKey( t ) ) PrintTable( table.SortByKey( t , true ) )
Output:
1 = a 2 = x 3 = h
1 = h 2 = x 3 = a