title: Javascript bubble sort of an array with objects
body: <p>beginner here!</p>
  
  <p>Recently stumbled upon a problem. Basically, the program needs to sort an array of objects by one of their fields without actually using the sort function. I've tried this code using bubble sort algorithm, but it doesn't seem to be working:</p>
  
  <pre><code>var arrayOfPeople = [
      {name: "Rick", age: 30, place: 2},
      {name: "Alan", age: 25, place: 1},
      {name: "Joe", age: 40, place: 4},
      {name: "Dave", age: 35, place: 3}
  ];
  
  
  function bubbleSort(a,par)
  {
      var swapped;
  
      do {
          swapped = false;
  
          for (var i = 0; i &lt; a.length - 1; i++) {
              if (a[i].par &gt; a[i + 1].par) {
                  var temp = a[i];
  
                  a[i] = a[i + 1];
                  a[i + 1] = temp;
  
                  swapped = true;
              }
          }
      } while (swapped);
  }
  
  
  bubbleSort(arrayOfPeople,'age');
  
  for (i = 0; i &lt; arrayOfPeople.length; i++) {
      console.log(arrayOfPeople[i]);
  }
  </code></pre>
  
  <p>My guess is that I'm doing something wrong syntax-wise. Will appreciate any feedback.</p>