Sort an arbitrary array of arrays