Hello
I have a problem with the sorting of a table by using a function. I tried to create a function that sorts the contents of the table from the largest to the smallest value. But I failed. So far I have only rarely used tables and I’m slightly awkward in this area. I would very happy if someone can help me.
function setup()
tab={34,23,65,74,12,26}
print("Current table order")
for x,y in pairs(tab) do
print(x,y)
end
print()
print("Sorted high to low")
table.sort(tab,highLow)
for x,y in pairs(tab) do
print(x,y)
end
print()
print("Sorted low to high")
table.sort(tab,lowHigh)
for x,y in pairs(tab) do
print(x,y)
end
end
function highLow(a,b)
return a>b
end
function lowHigh(a,b)
return a<b
end