Sort hash by length of contained values
ruby
Solution
I'd just do this:
Hash[foo.sort_by { |k, v| v.join.length }]
I assume you're not intending the change the original Hash values, just re-order them.
Problem
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`