How to order array based on category? : <p>I've got the following array of objects:</p>

<pre><code>var source =  [
  {"name": "title_1", "category": "order"},
  {"name": "title_2", "category": "purchase"},
  {"name": "title_3", "category": "order"},
  {"name": "title_4", "category": "detail"},
  {"name": "title_5", "category": "order"},
  {"name": "title_6", "category": "purchase"},
]
</code></pre>

<p>I need to sort this array out to get elements in order (first - orders, second - detail, third - purchase):</p>

<pre><code>console.log(source.sort(function () {
   // todo: ?
}))
</code></pre>

<p><em>Expected result:</em></p>

<pre><code>[
  {"name": "title_1", "category": "order"},
  {"name": "title_3", "category": "order"},
  {"name": "title_5", "category": "order"},
  {"name": "title_4", "category": "detail"},
  {"name": "title_2", "category": "purchase"},
  {"name": "title_6", "category": "purchase"},
]
</code></pre>

<p>How to write sort function to get expected result?</p>
