From: Pradeep Jindal Date: 2006-11-27T19:58:37+09:00 Subject: Re: find index of first non zeo value in array On Sunday 26 November 2006 21:22, Park Heesob wrote: > Hi, > > >From: Josselin > >Reply-To: ruby-talk@ruby-lang.org > >To: ruby-talk@ruby-lang.org (ruby-talk ML) > >Subject: find index of first non zeo value in array > >Date: Sun, 26 Nov 2006 23:00:10 +0900 > > > >with : > >array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, > > 0, 0, 0, 0, 0] > > > >I wrote : > >array.index(array.detect {|x| x > 0}) => 15 > > > >is there a better and simpler way to do it ? > >thanks > > > >joss > > How about this: > > array.index((array-[0])[0]) > > Regards, > > Park Heesob > > _________________________________________________________________ > Don't just search. Find. Check out the new MSN Search! > http://search.msn.com/ Not a generic way, but pretty good for this specific problem. Regards, Pradeep