From: Daniel Schierbeck Date: 2006-06-08T23:42:59+09:00 Subject: Re: Easy question Robert Mela wrote: > With inject, aren't you iterating over the entire array every time you > add a new point, such that series.add(p) becomes O n^2? Yes, I didn't see that until after i posted :( I actually did the #(max|min)_(x|y) thing first, and then just copied the code after re-reading your post. My bad. Robert Mela wrote: > @points is an array of point objects > > class Point > :attr_reader :x, :y > def initialize( x, y ) > @x, @y=x,y > end > end def max_x @points.inject{|max, cur| cur.x > max.x ? cur : max}.x end I'd personally use that approach -- but if you're accessing the method often, it's rather inefficient. Daniel