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) } p array #=> [1, 3, 7, 4] index = -2, -1 i = -(array.size + 1) array.delete_if{ index.delete(i+=1) } p array #=> [1, 3] cfp:~ > ruby a.rb [1, 3, 7, 4] [1, 3] this approach avoids any sorting or extra copying and also does the deletion in one pass. regards. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama