I want to sort a table based on two comparison operations.
I want to first sort the table by rank numerically, and then sort it by color alphabetically.
So the order would be,
I am aware of this function,
but don't know how to do a more complicated sort.
t = {
[1] = { fruit = pear, color = red, rank = 0 },
[2] = { fruit = apple, color = orange, rank = 1 },
[3] = { fruit = orange, color = green, rank = 2 },
[4] = { fruit = potatoe, color = black, rank = 1 },
}
I want to first sort the table by rank numerically, and then sort it by color alphabetically.
So the order would be,
1 = orange, green, 2
2 = potatoe, black, 1
3 = apple, orange, 1
4 = pear, red, 0
I am aware of this function,
table.sort(t, function(a, b) return a.rank > b.rank end)
but don't know how to do a more complicated sort.