title: Javascript: Bubble Sort
body: <p>I have made a bubble sort algorithm (sorta) using JS. It works sometimes, but the problem is that it only iterates through the array once. Here is my code:</p>
  
  <pre><code>function bubble(arr) {
    for (var i = 0; i &lt; arr.length; i++) {
      if (arr[i] &gt; arr[i + 1]) {
        var a = arr[i]
        var b = arr[i + 1]
        arr[i] = b
        arr[i + 1] = a
      }
    }
    return arr;
  }
  </code></pre>