[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lhs and rhs in table.sort
- From: Jonathan Goble <jcgoble3@...>
- Date: Mon, 24 Aug 2015 17:26:24 -0400
On Mon, Aug 24, 2015 at 5:15 PM, Jonathan Goble <jcgoble3@gmail.com> wrote:
> table.sort( list, function( n1, n2 )
> local a = n1.confWins + n1.confLosses > 0 and n1.confWins /
> (n1.confWins + n1.confLosses) or 0.01
> local b = n2.confWins + n2.confLosses > 0 and n2.confWins /
> (n2.confWins + n2.confLosses) or 0.01
> if n1.wins + n1.losses > 0 and n2.wins + n2.losses > 0 and
> n1.wins / (n1.wins + n1.losses) ~= n2.wins / (n2.wins + n2.losses)
> then
> return n1.wins / (n1.wins + n1.losses) > n2.wins /
> (n2.wins + n2.losses)
> elseif a ~= b then
> return a > b
> elseif n1.h2hWins ~= n2.h2hWins then
> return n1.h2hWins > n2.h2hWins
> elseif n1.pointDiff ~= n2.pointDiff then
> return n1.pointDiff > n2.pointDiff
> elseif n1.pointsAllowed ~= n2.pointsAllowed then
> return n1.pointsAllowed < n2.pointsAllowed
> else
> return n1.randomNumber > n2.randomNumber
> end
> end )
(Oh, and feel free to laugh at my programming skills here. This
function was written on a deadline during my first week of learning
how to program in something other than BASIC, over two years ago.
Suffice it to say that I've learned a lot since then. :-P )