title: Sort an object on indices of an array in JavaScript?
body: <p>OK so given this input (other properties have been stripped for brevity):</p>
  
  <pre><code>var names = [{
      name: 'Michael'
  }, {
      name: 'Liam'
  }, {
      name: 'Jake'
  }, {
      name: 'Dave'
  }, {
      name: 'Adam'
  }];
  </code></pre>
  
  <p>I'd like to sort them by another array's indices, and if they aren't in that array, sort alphabetically.</p>
  
  <pre><code>var list = ['Jake', 'Michael', 'Liam'];
  </code></pre>
  
  <p>Giving me an output of:</p>
  
  <pre><code>Jake, Michael, Liam, Adam, Dave
  </code></pre>
  
  <p>I've tried using lo-dash but it's not quite right:</p>
  
  <pre><code>names = _.sortBy(names, 'name');
  names = _.sortBy(names, function(name) {
      var index = _.indexOf(list, name.name);
      return (index === -1) ? -index : 0;
  });
  </code></pre>
  
  <p>as the output is:</p>
  
  <pre><code>Jake, Liam, Michael, Adam, Dave
  </code></pre>
  
  <p>Any help would be really appreciated!</p>