As explained on stackoverflow it is not unexpected to compare the same element.
The comparison function shall implement a strict comparison (i.e. <, not <=).
E.g.:
``` lua
local arr = {
{id="A", v=1},
{id="B", v=1},
{id="C", v=0},
{id="D", v=1},
{id="E", v=1},
}
```
The index can be added to the array itself to avoid using an extra table:
``` lua
for idx, elem in ipairs(arr) do
elem.idx = idx
end
```
Then the array can be sorted with:
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lua-l/983abeaa-46af-4258-ba70-01ffb7843ae0n%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "lua-l" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lua-l/Y61Xo2i4MGk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lua-l+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lua-l/20240715155437.GB595440%40arraial.inf.puc-rio.br.