sorting a table in descending order in Lua -
sorting a table in descending order in Lua -
i can not work:
tbl = { [1] = { ['etc2'] = 14477 }, [2] = { ['etc1'] = 1337 }, [3] = { ['etc3'] = 1336 }, [4] = { ['etc4'] = 1335 } } = 1, #tbl table.sort(tbl, function(a, b) homecoming a[i] > b[i] end) print(tbl[i] .. '==' .. #tbl) end
getting error: effort compare 2 nil values
this follow-on table value sorting in lua
how this?
tbl = { { 'etc3', 1336 }, { 'etc2', 14477 }, { 'etc4', 1335 }, { 'etc1', 1337 }, } table.sort(tbl, function(a, b) homecoming a[2] > b[2] end) k,v in ipairs(tbl) print(v[1], ' == ', v[2]) end
organizing info way made easier sort, , note phone call table.sort
once, not 1 time per element of table. , sort based on sec value in subtables, think wanted.
sorting lua lua-table
Comments
Post a Comment