> Message: 4 > Date: Tue, 8 May 2007 23:18:00 -0600 > From: "Chris McMahon" <[EMAIL PROTECTED]> > Subject: [Wtr-general] OT: find min/max values in an array of floats > To: wtr-general@rubyforge.org > Message-ID: > <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > I can think of a couple of ways to do this, but they're all painful in > one way or another. Ruby being Ruby, I wonder if there's some nifty > shortcut. Given > > floats = [] > floats << 3.456 > floats << 1.53 > floats << 5.123 > > show that the least element of the array is 1.53 and the greatest > element of the array is 5.123, where the array "floats" can have an > arbitrarily large number of elements, of which all are (of course) > numbers with decimal values. > > > floats.sort!.last should get the maximum float value
_______________________________________________ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general