Say I have a hash like:
foo = {
:bar => ['r', 'baz'], # has a total str length of 4 characters inside of the array
:baz => ['words', 'etc', 'long words'] # has a total str length of 18 characters inside of the array,
:blah => ['at'] # has a total str length of 2 characters inside of the array
# etc...
}
How would I go about sorting this hash by the total string length of the items contained within the arrays? The resulting hash order in this case should be: :blah, :bar, :baz
I’d just do this:
I assume you’re not intending the change the original Hash values, just re-order them.