From: Todd Benson Date: 2007-11-08T13:11:23+09:00 Subject: Re: how to delete array On Nov 7, 2007 9:47 PM, ara.t.howard wrote: > > On Nov 7, 2007, at 1:40 PM, Surjit Nameirakpam wrote: > > > > Surjit Nameirakpam wrote: > >> My business logic doesn't help me find which values i have to > >> delete but > >> i will know what are the indexes i have to delete. > > > > Actually i have collected the indexes i have to delete in an array > > > > e.g > > > > Array1 = [1,2,3,4,7,4] > > > > indexes to be delted is collected in an array del=[1,3] ..i.e i should > > delete 2 and 4 values > > > > i tried using > > > > Array1.delete_at(del[]) > > > > but this doesn't work > > -- > > Posted via http://www.ruby-forum.com/. > > > > cfp:~ > cat a.rb > array = 1, 2, 3, 4, 7, 4 > > index = 1, 3 > i = -1 > array.delete_if{ index.delete(i+=1) } This is excellent! Only, what if your underlying implementation does not traverse an array in order with #delete_if ? As it turns out, it does, but would it have to? I see #delete_if as a conditional that has nothing to do with the Array's ordering, so I was a little surprised at this assumption. Todd