So I thought I understood this, but I'm not getting the output I expected, so obviously I don't understand it.
In Ruby (2.0.0)
a = [1,2,3,4]
a.each do |e|
a.delete(e)
end
a = [2,4]
It doesn't seem to be looping through each item in the array. However, when I simply output the item, it loops through each item. There's some mechanism of a.delete(e) that is affecting the iteration.
a = [1,2,3,4]
a.each do |e|
puts e
end
=> 1
=> 2
=> 3
=> 4
Ultimately, I want to put a conditional into the loop, such as:
a = [1,2,3,4]
a.each do |e|
if e < 3
a.delete(e)
end
end
How can I get this loop it iterate through each item and delete it? Thank you!