title: Insertion sort implementation in scala
body: <p>I'm trying out Scala and I want to see how one would implement insertion sort in scala with the following requirements:</p>
  
  <ol>
  <li>Nested for loops</li>
  <li>Array[Int] for input</li>
  <li>If possible a way to modify the contents of the function in a call by reference way otherwise return an Array[Int]</li>
  </ol>
  
  <p>If this isn't the Scala way of implementing insertion sort can you still provide code for the above and explain what is wrong with the approach.
  edit:
  This is an attempt using a while loop (doest work) and no it isn't a homework question, why the hostility?</p>
  
  <pre><code>def insert_sort(a:Array[Int]):Array[Int]={
  for(i &lt;- 0 until a.length)
  {
    var j=i+1
  
    while(j&gt;1&amp;&amp;a(j)&lt;a(j-1)&amp;&amp;j&lt;a.length)
    {
        var c=a(j)
        a(j)=a(j-1)
        a(j-1)=c
        j-=1
    }
  }
  return a
  }
  </code></pre>