title: How to implement a javascript grouped team sort?
body: <p>I'd like to implement a sort function for an array of teams where teams are to be sorted based on a substring of the team name and then sorted by group.  As an example, the array might look like this:</p>
  
  <pre><code>["Project Team This", "Support Team Other", Project Team Another", "Project Directors", "Support Directors", "Project Team Other", "Support Team That"]
  </code></pre>
  
  <p>I'd like to sort them where "Directors" groups are first, "Project" groups are second and "Support" groups third, but then maybe alphabetically sorted within those groupings.  In addition, I'd actually like Project Directors first,  So the output would be:</p>
  
  <pre><code>Project Directors,
  Support Directors,
  Project Team Another,
  Project Team Other,
  Project Team This,
  Support Team Other,
  Support Team That,
  </code></pre>
  
  <p>Essentially the order is:</p>
  
  <ol>
  <li>Project Directors</li>
  <li>Anything else with "<em>directors</em>" in it</li>
  <li>Anything with "<em>project</em> in it</li>
  <li>Anything with "<em>support</em>" in it</li>
  </ol>
  
  <p>I was thinking an Insertion sort of some kind would be the way to go?  How would you implement this?</p>
  
  <p>Any suggestions you have greatly appreciated.</p>
  
  <p>Many thanks.</p>
  
  <p><strong>Update 1:</strong> I tried a compare function on the standard sort as follows.  I think I probably need to actually break them into separate groups first to sort them alphabetically as suggested by Adam.</p>
  
  <pre><code>function teamSort(a, b) {
      left = a.toLowerCase();
      right = b.toLowerCase();
      if (left.includes('project directors')) {
          return -1;
      }
      if (right.includes('project directors')) {
          return 1;
      }
      if (left.includes('project team')) {
          return -1;
      }
      if (right.includes('project team')) {
          return 1;
      }
      return 0;
  }
  </code></pre>
  
  <p><strong>Update 2</strong>: As suggested by Adam, this time splitting them out into separate arrays, sorting and then concatenating. </p>
  
  <pre><code>function teamSort2(teams) {
      let supportTeams = teams.filter(t =&gt; {
          return t.toLowerCase().includes('support');
      });
      let projectTeams = teams.filter(t =&gt; {
          return t.toLowerCase().includes('project team');
      });
      let projectDirectors = teams.filter(t =&gt; {
          return t.toLowerCase().includes('project directors');
      });
      let otherDirectors = teams.filter(t =&gt; {
          return t.toLowerCase().includes('directors') &amp;&amp; !t.toLowerCase().includes('project directors');
      });
  
      supportTeams.sort();
      projectTeams.sort();
      otherDirectors.sort();
  
      return projectDirectors.concat(otherDirectors, projectTeams, supportTeams);
  }
  </code></pre>
  
  <p>Any better ways to do this?</p>