On Fri, Apr 24, 2009 at 9:38 AM, Rob Redmon <rob.webinator / gmail.com> wrote=
:
> [...]
> Find the two elements in a1 who are nearest neighbors to the scalar
> s. =A0I need the indices more than the values.
>
> Clearly, I can find the nearest values with this:
>>> [10,20,30,40,50].find_all{|item| item >=3D 25 }.first
> =3D> 30
>>> [10,20,30,40,50].find_all{|item| item <=3D 25 }.last
> =3D> 20
>
> How do I get the matched indices? =A0That is, without ugly loops.

#index and #rindex in their block forms come to mind:
http://ruby-doc.org/core-1.9/classes/Array.html#M001974

cheers,
lasitha