G.SortedPairsByValue

From GMod Wiki

Jump to: navigation, search
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: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=G.SortedPairsByValue]G.SortedPairsByValue [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionIterate through a table in order of its values
Used onNewerShared.png
Code
local TestTable = {b=2,c=1,a=3}
for k,v in SortedPairsByValue(TestTable) do
  print(k,v)
end
Output1 1

1 2

1 3
DescriptionIterate through a table in reverse order of its values
Used onNewerShared.png
Code
local TestTable = {b=2,c=1,a=3}
for k,v in SortedPairsByValue(TestTable, true) do
  print(k,v)
end
Output1 3

2 2

3 1


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox