From: Joshua Collins Date: 2009-05-14T15:55:12+09:00 Subject: Re: find previous & next in array --001e680f1828d154ce0469d9ce6c Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Boby had it almost right! instead of: a[a.index(:c)+1] it is: a[a.index('c')+1] :-) On Wed, May 13, 2009 at 11:48 PM, Boby Selamet Hartono wrote: > 2009/5/14 John Griffiths > > > hi, anyone know how to do this? > > > > basically i've got an array of items > > > > a = ['a','b','c','d'] > > > > now given i can find the position of say 'c' using .index('c'), how do i > > get the positions of the ones previous & next to it. > > > > a recursive routine would probably do it, but looking for something more > > flash > > > > any ideas? > > -- > > Posted via http://www.ruby-forum.com/. > > > > > a[a.index(:c)-1] or a[a.index(:c)+1]? > > -- > Tidak ada yang lebih baik dari kembali ke asal > Nothing can be better than back to the roots > --001e680f1828d154ce0469d9ce6c--