G.SortedPairsByValue
From GMod Wiki
| Function | |
| Syntax |
SortedPairsByValue( Table table, Boolean reverse ) Where is this used? |
| Description: | |
| Generates an iterator for traversing tables in value order | |
| Returns: | Function iterator, Table state |
| Part of Library: | Global Functions |
| Realm: |
|
| BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=G.SortedPairsByValue]G.SortedPairsByValue [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Examples
| Description | Iterate through a table in order of its values |
|---|---|
| Used on | |
| Code | local TestTable = {b=2,c=1,a=3} for k,v in SortedPairsByValue(TestTable) do print(k,v) end |
| Output | 1 1
1 2 1 3 |
| Description | Iterate through a table in reverse order of its values |
|---|---|
| Used on | |
| Code | local TestTable = {b=2,c=1,a=3} for k,v in SortedPairsByValue(TestTable, true) do print(k,v) end |
| Output | 1 3
2 2 3 1 |
Additional Notes
- This discards the original keys from the table, unlike SortedPairs, this may be a bug