title: Bubble sort javascript code need explanation little
body: <p>I'm writing a bubble sort program for fun but what i don't understand is
  the line <code>j&lt;len-i</code> does in this code?</p>
  
  <p>i can just remove -i from the above line it will also work,</p>
  
  <pre><code>var arr=[3,5,4,7,8,9,30,0,-1];
  function bubble_Sort(arr){
  
  var len = arr.length,
      i, j, stop;
  
  for (i=0; i &lt; len; i++){
      for (j=0; j&lt;len-i;  j++){
          if (arr[j] &gt; arr[j+1]){
              var temp=arr[j];
              arr[j]=arr[j+1];
              arr[j+1]=temp;
  
          }
      }
  }
  
  return arr;
  }
  console.log(bubble_Sort(arr));
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//with -i in second for loop
  var arr=[3,5,4,7,8,9,30,0,-1];
  function bubble_Sort(arr){
  
      var len = arr.length,
          i, j, stop;
  
      for (i=0; i &lt; len; i++){
          for (j=0; j&lt;len-i;  j++){
              if (arr[j] &gt; arr[j+1]){
                  var temp=arr[j];
                  arr[j]=arr[j+1];
                  arr[j+1]=temp;
                  
              }
          }
      }
  
      return arr;
  }
  console.log(bubble_Sort(arr));</code></pre>
  </div>
  </div>
  </p>
  
  <p>Without -i in second loop</p>