title: Performing a manual sort on an Array
body: <p>I'm using OpusScript, which is very similar to Javascript.</p>
  
  <p>I need to sort an Array by two properties of the objects within it.</p>
  
  <p>The object type of the array is 'ScoreEntity', with the properties Score and Time. I need the highest score at the 0 index of the array and vise versa, with the faster time overriding matching scores.</p>
  
  <p>I've been trying to do this for ages and I cant get my head around it, I've got Saturday Syndrome!</p>
  
  <p><strong>ANSWER:</strong></p>
  
  <p>I used BubbleSort in the end, any comments on improving this are welcome.</p>
  
  <pre><code>function SortScoreArray(array)
  {
  
      var unsorted = true
      while (unsorted)
      {
  
          // Tracks whether any changes were made, changed to false on any swap
          var complete = true
          for (var i = 0; i &lt; array.length - 1; i++)
          {           
  
              // Holds the value for determining whether to swap the current positions
              var swap = false
  
              var currentItem = array[i]
              var nextItem = array[i + 1]
  
              if (currentItem.Score == nextItem.Score)
              {
  
                  // The scores are the same, so sort by the time
                  if (currentItem.Time &gt; nextItem.Time)
                  {
                      swap = true
                  }
  
              }
              else if (currentItem.Score &lt; nextItem.Score)
              {
                  swap = true
              }
  
  
              if (swap)
              {
                  array[i] = nextItem
                  array[i + 1] = currentItem
                  complete = false
              }
  
          }
  
          if (complete)
          {
              unsorted = false
          }
  
      }
  
      return array
  
  }
  </code></pre>