I have an Array of Array , which I want to sort by length to the shortest. I achieved this quite easily with sort_by
> a = [ [1, 2, 9], [4, 5, 6, 7], [1, 2, 3] ] > a.sort_by(&:length).reverse
I want, however, to have a kind of tie-break for lists of the same length. If the length of the two lists is the same, the list whose last record is longer should be the first. Thus, in the above case, you should switch [1, 2, 9] and [1, 2, 3] .
I don't care when two lists have equal length and equal last element, they can be in any order if that happens. I don't know how and how I can achieve this with ruby's built-in sort.
source share