title: Filter and sort a JavaScript array
body: <p>I have an array like this:</p>
  
  <pre><code>[{
      "number": "4",
      "fileName": "fileXX",
      "rating": {
          "average": 6.4
      }
  }, {
      "number": "3",
      "fileName": "fileXX",
      "rating": {
          "average": 5.4
      }
  }, {
      "number": "4",
      "fileName": "fileXX",
      "rating": {
          "average": 5.4
      }
  }]
  </code></pre>
  
  <p>I am trying to create a new array with the following criteria:</p>
  
  <ol>
  <li>Get highest rating (<code>array.rating.average</code>) of each number (<code>array.number</code>)</li>
  </ol>
  
  <p>Output should be:</p>
  
  <pre><code>[{
      "number": "4",
      "fileName": "fileXX",
      "rating": {
          "average": 6.4
      }
  }, {
      "number": "3",
      "fileName": "fileXX",
      "rating": {
          "average": 5.4
      }
  }
  }]
  </code></pre>
  
  <p>I have just managed to sort by highest rating:</p>
  
  <pre><code>array.sort(function(a , b) {
      return a.rating.average - b.rating.average;
  });
  array.reverse();
  </code></pre>
  
  <p>But, now, I just only want one object per duplicate <code>array.number</code>, keeping the one that has the highest <code>array.rating.average</code>.</p>