title: JavaScript BubbleSort, how to improve its efficiency?
body: <p>Have a bubblesort routine similar to this. I need to make it more efficient by stopping the loop when the array is sorted or if the array is already sorted. </p>
  
  <pre><code>function sortNumbers(listbox) {
    var x, y, holder;
    // The Bubble Sort method.
    for(x = 0; x &lt; ranarray.length; x++) {
      for(y = 0; y &lt; (ranarray.length-1); y++) {
        if(ranarray[y] &gt; ranarray[y+1]) {
          holder = ranarray[y+1];
          ranarray[y+1] = ranarray[y];
          ranarray[y] = holder;
        }
      }
    }
  </code></pre>