Hi,
I’m trying to sort a table like this:
local competitions = {
{category = “Libertadores”, state = “finished”},
{category = “Champions”, state = “timed”},
{category = “Sudamericana”, state = “timed”},
{category = “Libertadores”, state = “timed”}
}
via :
local sort\_function = function( a,b ) if (b.state == "finished") and (a.state ~= "finished") then return b.stage \< a.stage end end table.sort( competitions, sort\_function)
I would like to obtain this result:
{category = “Champions”, state = “timed”},
{category = “Sudamericana”, state = “timed”},
{category = “Libertadores”, state = “timed”},
{category = “Libertadores”, state = “finished”}
But i am obtaining this:
{category = “Libertadores”, state = “timed”},
{category = “Sudamericana”, state = “timed”},
{category = “Champions”, state = “timed”},
{category = “Libertadores”, state = “finished”}
What I want is that when the state is “finished” I send the object to the end of the array but I leave the other positions in the order they were
Can anyone help me to solve this?
Thanks!