Can anyone try to solve this problems?

[‘fodfsafdfsdfso’,‘bar’,‘bazzzzzz’].sort_by { |s| s.length }.pop

The beauty of a one line solution :slight_smile:

also…what is this about:

max_by(&:length)

Dave.

Daniel M. wrote:

Why build up a separate hash structure?

It’s simpler to my eyes. It’s also (admittedly unintuitively) faster
though.

Here’s a quick test with your version, my original, and another going
off your idea, but I tried to simplify it a bit:

bm.report { puts a.max_by3 &:size }
end

I couldn’t tell you why the 3rd is so much faster than the first. Just
goes to prove the old programming adage though: “Optimizing before
Profiling is a waste of time.”

Not that this counts as serious profiling of course. :slight_smile: