How do I sort a 2D array by the length of its inner elements? The number of inner elements is not the same.
Example:
a = [[1], [2, 3], [4, 5, 6, 7], [8,
Try this:
a = [[1], [2, 3], [4, 5, 6, 7], [8, 9]] a.sort { |x, y| y.size <=> x.size } #=> [[4, 5, 6, 7], [2, 3], [8, 9], [1]]