lost = {1,6,0,8,2,5}
table.sort(lost, function(a, b)
return lost[a] < lost[b]
end)
for i, v in pairs(lost) do
print(i, v)
end
✓ ANSWER ACCEPTED
Why is this not sorting the table?
1 answer
✓ Accepted answer
You have interpreted wrong how table.sort works. The values passed to the functions are not the indices, but in fact, the values! (That is, lost[a] will be a, and lost[b] is b).
What you mean is:
lost = {1,6,0,8,2,5}
table.sort(lost, function(a, b)
return a < b
end)
for i, v in pairs(lost) do
print(i, v)
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
THANK YOU !