title: Conditionally inserting data into an array
body: <p>Alright, can someone help me how to properly iterate a dynamic size array?
  Here's what I mean:</p>
  
  <pre><code>my_array = [1, 2, 3, 4, 2, 5, 15, 2] # &lt;= there are three 2 inside my_array 
  </code></pre>
  
  <p>Then I would like to add "good" everytime the iteration hit integer 2, I tried several method but not find the way, here's the best method I've tried(still not resulting in what I want)</p>
  
  <pre><code># First Method
  for i in 0..(my_array.length - 1)
   my_array.insert(i + 1, "good") if my_array[i] == 2
  end
  
  p my_array # =&gt; [1, 2, "good", 3, 4, 2, "good", 5, 15, 2] 
  
  # Second Method
  for i in 0..(my_array.length - 1)
   my_array[i + 1] = "good" if my_array[i] == 2
  end
  
  p my_array # =&gt; [1, 2, "good", 4, 2, "good", 15, 2, "good"] 
  </code></pre>
  
  <p>The first method is not good because it's not showing "good" after the last 2, I guess this because the iteration could not reach the last integer 2(in the last array) and that is expected because the array size is changed bigger everytime "good" is inserted. </p>
  
  <p>The second one is also bad, because I replace the data after every 2 with "good" string.
  Now can someone point it out to me how can I doing this properly so I can produce it like this:</p>
  
  <pre><code> p my_array # =&gt; [1, 2, "good", 3, 4, 2, "good", 5, 15, 2, "good"]
  </code></pre>
  
  <p>All "good" is added without replacing any data.</p>
  
  <p>Any help is appreciated, thank you very much.</p>