title: How to properly iterate over arrays in kotlin
body: <p>I am currently learning kotlin and therefore following the kotlin track on exercism. The following <a href="https://exercism.io/my/solutions/5a915f3cf5604a7eb42fc4bb6e17b933" rel="nofollow noreferrer">exercise</a> required me to calculate the Hamming difference between two Strings (so basically just counting the number of differences).</p>
  
  <p>I got to the solution with the following code:</p>
  
  <pre><code>object Hamming {
      fun compute(dnaOne: String, dnaTwo: String): Int {
          if (dnaOne.length != dnaTwo.length) throw IllegalArgumentException("left and right strands must be of equal length.")
          var counter = 0
          for ((index, letter) in dnaOne.toCharArray().withIndex()) {
              if (letter != dnaTwo.toCharArray()[index]) {
                  counter++
              }
          }
          return counter
      }
  }
  </code></pre>
  
  <p>however, in the beginning I tried to do <code>dnaOne.split("").withIndex()</code> instead of <code>dnaOne.toCharArray().withIndex()</code> which did not work, it would literally stop after the first iteration and the following example 
  <code>Hamming.compute("GGACGGATTCTG", "AGGACGGATTCT")</code> would return 1 instead of the correct integer 9 (which only gets returned when using <code>toCharArray</code>) </p>
  
  <p>I would appreciate any explanation</p>