Example Table
{{"Random String", 8},{"Random String2", 14},{"Random String3", 3}}
What is the best way to sort the table so it returns {"Random String3", 3} because it's second value is the smallest?
Currently I am using this script, but it seems very inefficient
local smallestF = math.huge
for mynodeSpot,mynode in pairs(specificOpenList) do
if mynode[9] < smallestF then
smallestF = mynode[9]
currentNode = mynode
currentNodeSpot = mynodeSpot
end
end
I did some research and found this
> mytable = {2,4,6,24,7,5}
> print(math.min(unpack(mytable)))
2
However, when using the type of table that I am using, it doesn't work. For some reason it returns the 8, which isn't the smallest value, and even if it did I would want the whole table so I can access the string attached to it.
> mytable = {{"Random String", 8},{"Random String2", 14},{"Random String3", 3}}
> print(math.min(unpack(mytable)[2]))
8
What is the best way to do this?

2 comments
Why don't you use a dictionary instead of what you're doing currently?
How would I do it? Maybe I could, but I use the table for other things so reorganizing it would cause a lot more problems than it would solve.