title: Javascript Binary Search/Insertion Preformance
body: <pre><code>function binarySearch(value)
  {
      var startIndex = 0,
          stopIndex = words.length - 1,
          middle = Math.floor((stopIndex + startIndex) / 2);
  
      while (words[middle] != value &amp;&amp; startIndex &lt; stopIndex) {
          // adjust search area
          if (value &lt; words[middle]) {
              stopIndex = middle - 1;
          } else if (value &gt; words[middle]) {
              startIndex = middle + 1;
          }
  
          // recalculate middle
          middle = Math.floor((stopIndex + startIndex) / 2);
      }
  }
  </code></pre>
  
  <p>I am making a large list of words in the format of an array:</p>
  
  <p>e.g. <code>["a","ab","abc","b"]</code></p>
  
  <p>In alphabetical order. The problem I'm having is modifying my binary search algorithm to add the word in the correct place and then update?</p>
  
  <p>Whats the best way performance-wise to add a word into an ordered array? And why is it the best way to do it?</p>