botp
8/26/2007 3:54:00 PM
On 8/25/07, Stefan Rusterholz <apeiros@gmx.net> wrote:
> Peña, Botp wrote:
> > ar2 = ar1.collect { |x| x<45000 ? (x + incVal) : x}
> > or
> > ar2 = ar1.collect { |x| if x<45000 then (x + incVal) else x end}
> > or
> > ar2 = ar1.select{|x| x<45000}.collect{|x| x + incVal}
> >
> > i usually prefer the last one, since i think like: "select those
> > elements < 45000, then with those collections, increment each". but that
> > is just me.
> >
> > welcome to ruby.
> > kind regards -botp
>
> The last one is not equivalent to the other two. It will drop values >=
> 45000.
oops. mea culpa. what was i thinking again :( yes, pls ignore the
last one. at least i may be right on the testing part :))
kind regards -botp