title: JavaScript Array Sorting/Ranking with Equal Ranks
body: <p>After sorting an array of objects based on of their property values ("rating" in this case), how do you associate ranks for each object if there are ties between some of these values? Here's an example:</p>
  
  <pre><code>//Should be tied for 1st Rank
  var obj1 = { 
    name: "Person1",
    rating: 99
  }
  
  //Should be 3rd Rank
  var obj2 = {
    name: "Person2",
    rating: 50
  }
  
  //Should be 2nd Rank
  var obj3 = {
    name: "Person3",
    rating: 98
  }
  
  //Should be 4th Rank
  var obj4 = {
    name: "Person4",
    rating: 0
  }
  
  //Should be tied for 1st Rank
  var obj5 = {
    name: "Person5",
    rating: 99
  }
  </code></pre>
  
  <p>Here's as far as I got:</p>
  
  <pre><code>var clients = [obj1, obj2, obj3, obj4, obj5];
  var sorted = [];
  
  for (var i = 0; i &lt; clients.length; i++) {
    sorted.push(clients[i]);
  }
  
  sorted.sort(function(a, b) {
    return b.rating-a.rating;
  });
  </code></pre>
  
  <p>Ultimately, I'd like to be able to get the rank using the object name, like this:</p>
  
  <pre><code>alert(sorted.indexOf(obj5) + 1);
  </code></pre>