There is nothing obvious about what's going on there, rchou2. Although it solves your problem (I think), it's not a very good answer because it's hard to explain and to understand. That's nothing in my favor - I can't immediately think of the way I would have done it before learning this trick.
Read more about the Schwartzian Transform to understand it. Especially, try to understand why it changes everything to remove the square brackets as you did in your cut and paste (you need them, to create the temporary arrays that are being used for sorting).