From: Daniel Finnie Date: 2007-01-16T09:10:22+09:00 Subject: Re: Can anyone try to solve this problems? That is the classic searching algorithm (almost). However there is something more idiomatic. Here's an example to find the biggest number: [1, 2, 3].max {|a, b| a <=> b } Try to adapt the array contents in that and the block to find the longest string. Dan David Madden wrote: > >> 2. Write a function to find the longest string in an array of strings. >> > Is this from the Brian Schroder Ruby Course PDF? > > Here is my function (no doubt a better on exists): > > def longest(a) > word = '' > a.each do |i| > if word.length < i.length > word = i > end > end > word > end > > > a = ['a', 'fish', 'is', 'messy', 'dog'] > > puts longest(a) > > > > >