title: TypeScript: Sort Array 1 by indexOf value from Array 2
body: <p>I'm new to Typescript/JavaScript so I'm sure I'm missing something easy.</p>
  
  <p>I have an array of 2 types, each of which has a sub-array of 3 - 4 names:</p>
  
  <pre><code>myArray = [
  {
      "type": "abc",
      "names": {
          "Jane Smith": 5,
          "John Doe": 3,
          "Jack Jones": 2
      }
  },
  {
      "type": "xyz",
      "names": {
          "Jane Smith": 3,
          "John Doe": 7,
          "Jack Jones": 3
      }
  }
  ];
  </code></pre>
  
  <p>I need to know which main type has the highest overall total and show that first.  In this example "xyz" has the highest total ((3 + 7 + 3) vs. (5 + 3 + 2)). So I'd want to display xyz before abc.</p>
  
  <p>I am successfully getting the totals of the two and putting them into a new array called totalValues:</p>
  
  <pre><code>totalValues = [
  {
      "type": "xyz",
      "count": 13            
      }
  },
  {
      "type": "abc",    
      "count": 10            
      }
  }
  ];
  </code></pre>
  
  <p>The problem is that I need to sort my original array (myArray) by type based on the total and I can't figure it out.</p>
  
  <pre><code>let sortedTotalValues = totalValues.sort().reverse();    //highest value first
  
  let sortedGroupNames = null;
  
  sortedGroupNames = myArray.sort((a, b) =&gt; {            
      return sortedTotalValues[0].indexOf(a) - sortedTotalValues[0].indexOf(b);
  });
  </code></pre>
  
  <p>Any help would be much appreciated.</p>