title: Why does is the index of the array repeatedly be printed out to be 2?
body: <p>I'm working on this function:</p>
  
  <p>It's supposed to take in an array and match it with a given word to see if that word can be formed with the given array of strings.</p>
  
  <p>I added the two commented lines because I wanted to see how the for-loop works.</p>
  
  <pre><code>def canformword(arr,word)
    arrword = word.chars
    arrleft = arr
    flag = true
    for i in 0...arrword.size
      ch = arrword[i]
      # puts arrword[i]
      if !arrleft.include?(ch)
        flag = false
        break
      else
        ind = arrleft.index(ch)
        # puts ind
        arrleft.delete_at(ind)
      end
    end
    if flag
      puts 'can form word'
    else
      puts 'can not form word'
    end
  end
  
  canformword(['y','b','z','e','a','u','t'], 'beauty')
  canformword(['r','o','u','g','h'], 'tough')
  </code></pre>
  
  <p>When I uncomment those two lines, the following is the output:</p>
  
  <p><strong>Why does the output print out the index 2 repeatedly? I would think that it would print out the index of each letter in my arrleft array rather than repeatedly spitting out 2!</strong></p>
  
  <p>I understand the 1 it prints out, because that's the index of b, but the rest is weird to me.</p>
  
  <pre><code>b
  1
  e
  2
  a
  2
  u
  2
  t
  2
  y
  0
  can form word
  t
  can not form word
  </code></pre>