Answer the question
In order to leave comments, you need to log in
How to explain the result of executing the code (element by element)?
There is an initial array:
There is a code:a = [1, 1, 1, 1, 1, 2, 2, 2, 5, 5, 6]
a.each do |item|
a[item] += 1
end
a = [1, 4, 6, 1, 1, 4, 3, 2, 5, 5, 6]
Answer the question
In order to leave comments, you need to log in
a = [1, 1, 1, 1, 1, 2, 2, 2, 5, 5, 6]
There are 11 iterations in total.
#1
a[1] += 1
#a = [1, 2, 1, 1, 1, 2, 2, 2, 5, 5, 6]
a[2] += 1
#a = [1, 2, 2, 1, 1, 2, 2, 2, 5, 5, 6]
a[2] += 1
#a = [1, 2, 3, 1, 1, 2, 2, 2, 5, 5, 6]
a[1] += 1
#a = [1, 3, 3, 1, 1, 2, 2, 2, 5, 5, 6]
a[1] += 1
#a = [1, 4, 3, 1, 1, 2, 2, 2, 5, 5, 6]
a[2] += 1
#a = [1, 4, 4, 1, 1, 2, 2, 2, 5, 5, 6]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question