title: Sorting with priority in jquery or js
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var data = [{
    "type": "local",
    "name": "Frank",
    "age": 89
  }, {
    "type": "visitor",
    "name": "Mary",
    "age": 76
  }, {
    "type": "local",
    "name": "John",
    "age": 36
  }, {
    "type": "visitor",
    "name": "James",
    "age": 10
  }, {
    "type": "local",
    "name": "Lily",
    "age": 17
  }, {
    "type": "visitor",
    "name": "Harry",
    "age": 67
  }, {
    "type": "local",
    "name": "Larry",
    "age": 7
  }, {
    "type": "visitor",
    "name": "Harold",
    "age": 37
  }]
  
  var sort_by = function(field, reverse, primer) {
  
    var key = primer ?
      function(x) {
        return primer(x[field])
      } :
      function(x) {
        return x[field]
      };
  
    reverse = !reverse ? 1 : -1;
  
    return function(a, b) {
      return a = key(a), b = key(b), reverse * ((a &gt; b) - (b &gt; a));
    }
  }
  
  
  data = data.sort(sort_by('age', true, parseFloat));
  console.log(JSON.stringify(data))</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is my how I sort my data. Currently what it does is sort the age from oldest to youngest. It is doing fine as it is. I found this sorting in some post in SO.</p>
  
  <p>I want to add another requirement on the process. I want to first be able to find all with type local sort it from oldest to youngest <strong>meaning all local first from oldest to youngest</strong> then after sorting all the local.. Sort the rest from oldest to youngest still.</p>
  
  <p><code>UPDATE</code>:</p>
  
  <p>There will is another type but it doesnt matter here because All I need is to first make all the local at first in the list but still in oldest to youngest and then the rest is still in oldest to youngest.</p>