Created
July 12, 2013 08:12
-
-
Save ethicalhack3r/5982734 to your computer and use it in GitHub Desktop.
The array size decreases on delete, however, the 'internal loop counter' stays the same.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=[1,2,3,4]; a.each_with_index{|e,i| p "Iteration #{i}: delete #{e} - size of array #{a.size}"; a.delete(e) } | |
"Iteration 0: delete 1 - size of array 4" | |
"Iteration 1: delete 3 - size of array 3" | |
=> [2, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment