I am getting an unexpected result to the following
a= Array.rand(20,1,14)
a.do({|item,i| if (item < 5, {a.removeAt(i)})})
I would expect that all values lower then 5 would be expunged from a. that is almost what i get
before
→ [ 6, 7, 3, 1, 13, 14, 9, 9, 14, 2, 7, 2, 8, 3, 8, 3, 7, 6, 14, 9 ]
after
→ [ 6, 7, 1, 13, 14, 9, 9, 14, 7, 8, 8, 7, 6, 14, 9 ]
I suspect the 1 is still there because it appears after the 3 but I don’t understand why.
I am aware that select would work better in this case. However, in the actual case I will have two corresponding lists a and b and I will need to expunge values lower then x from a and the corresponding (i.e. in the same position) values from b. So the real code will also remove an item from b.