You cannot sort by numeric value ( but ). The key insight: compare two numbers and by checking if when concatenated as strings.
For and : compare vs . Since , should come before .
This comparison is transitive, so standard sorting algorithms work correctly with this custom comparator.