[Space Lua] Fix: table.sort comparator returns 0 for ties, not 1
Returning `1` when the comparator yields `false`/`nil` declares `a > b` for equal elements. `asyncQuickSort` tolerates this today but any future sort algorithm change could corrupt results. Changed to `0` so ties are neutral. Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
This commit is contained in:
@@ -185,6 +185,9 @@ do
|
||||
table.sort(t, function(a, b) return a > b end)
|
||||
assertEqual(t, { 3, 2, 1 })
|
||||
|
||||
table.sort(t, function(a, b) return a < b end)
|
||||
assertEqual(t, { 3, 2, 1 })
|
||||
|
||||
local data = { { name = "John", age = 30 }, { name = "Jane", age = 25 } }
|
||||
table.sort(data, function(a, b) return a.age < b.age end)
|
||||
assertEqual(data[1].name, "Jane")
|
||||
|
||||
Reference in New Issue
Block a user