From: Axel Etzold Date: 2007-10-03T16:59:41+09:00 Subject: Re: Searching through a sorted array -------- Original-Nachricht -------- > Datum: Wed, 3 Oct 2007 16:50:03 +0900 > Von: FireAphis > An: ruby-talk@ruby-lang.org > Betreff: Re: Searching through a sorted array > On Oct 3, 9:30 am, Peter Szinek wrote: > > FireAphis wrote: > > > Hello, > > > > > I have a very big array of objects sorted by one of its numeric data > > > members. During the flow of my application I need occasionally to get > > > all the elements in a specific range. > > > > Then why not > > > > my_array[start..end] ? > > > > Cheers, > > Peter > > __http://www.rubyrailways.comhttp://scrubyt.org > > Sorry if my explanation has been misleading. The array isn't > necessarily comprised of continuous or consecutive numbers. Moreover > they don't necessarily start from zero. For example: > > my_array = [-100, -99, -2, 0, 3, 125, 1742, 1234568763] > > now I want to get all the elements bigger than 1 and smaller than > 1000. AFAIK my_array[1..1000] doesn't help in this case. > In that case, you can say: interesting_array=my_array.delete_if{|entry| entry>1000 or entry<1} Best regards, Axel -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal f�r Modem und ISDN: http://www.gmx.net/de/go/smartsurfer