Implement sortByLength.