title: Khan academy: JavaScript loop taking too long
body: <p><a href="https://i.stack.imgur.com/9w3Ik.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9w3Ik.png" alt="enter image description here"></a></p>
  
  <p>I'm reading through the khan academy course on algorithms. I'm at <a href="https://www.khanacademy.org/computing/computer-science/algorithms/insertion-sort/p/challenge-implement-insertion-sort" rel="nofollow noreferrer">https://www.khanacademy.org/computing/computer-science/algorithms/insertion-sort/p/challenge-implement-insertion-sort</a>. So far I have:</p>
  
  <pre><code>var insert = function(array, rightIndex, value) {
  for(var j = rightIndex;
      j &gt;= 0 &amp;&amp; array[j] &gt; value;
      j--) {
      array[j + 1] = array[j];
  }   
  array[j + 1] = value; 
  };
  
  var insertionSort = function(array) {
  
  for(var i= 1;  i &lt; array.length ; i++ ) {
      insert(array, i ,array[i+1] );
  }
  
  };
  
  var array = [22, 11, 99, 88, 9, 7, 42];
  insertionSort(array);
  </code></pre>
  
  <p>You can see the line of code in the screenshot which appears to be the problem , but it looks fine to me. What am I doing wrong?</p>