# Multiple sort conditions

Simple question here: can table.sort return based on multiple true/false evaluations?

Like so:

``````local array = {1, 6, 57, 13, 212}

table.sort(array, function(a, b)
return a < b and a % 2 < b % 2
end)
``````

Would that order the table from least to greatest, even before odd?

Edit: I tried running a few sort conditions in the command bar, but something’s screwy:

``````local array = {1, 6, 57, 13, 212}

table.sort(array, function(a, b)
return a < b or a % 2 < b % 2
end)

print(table.unpack(array))

-- 6, 13, 57, 212, 1
``````

Everything there makes sense except for 1 being last. The condition should pass if the first number is either even or less than the second number, correct? One is obviously odd, but it’s less than every other member of the list, so why is it last in sort order? Am I a moron?

It’s because of your ordering function. Replace the 2 with 1.

Replace the 2 with 1? Do you mean:

``````a % 1 < b % 1
``````

Unless I’m mistaken, that’s the exact same as the first condition. % is the remainder operator, and the remainder of any number divided by 1, is, well, itself.