title: Sorting on a custom order
body: <p>I was wondering how I can sort an array on a custom order, not alphabetical. Imagine you have this array/object:</p>
  
  <pre><code>var somethingToSort = [{
      type: "fruit",
      name: "banana"
  }, {
      type: "candy",
      name: "twix"
  }, {
      type: "vegetable",
      name: "broccoli"
  }, {
      type: "vegetable",
      name: "carrot"
  }, {
      type: "fruit",
      name: "strawberry"
  }, {
      type: "candy",
      name: "kitkat"
  }, {
      type: "fruit",
      name: "apple"
  }];
  </code></pre>
  
  <p>In here we have 3 different types: fruit, vegetable and candy. Now I want to sort this array, and make sure that all fruits are first, candies come after fruits, and vegetables be last. Each type need their items to be sorted on alphabetical order. We will use a function like <code>sortArrayOnOrder ( ["fruit","candy","vegetable"], "name" );</code> So basically, you would end up with this array after sorting:</p>
  
  <pre><code>var somethingToSort = [{
      type: "fruit",
      name: "apple"
  }, {
      type: "fruit",
      name: "banana"
  }, {
      type: "fruit",
      name: "strawberry"
  }, {
      type: "candy",
      name: "kitkat"
  }, {
      type: "candy",
      name: "twix"
  }, {
      type: "vegetable",
      name: "broccoli"
  }, {
      type: "vegetable",
      name: "carrot"
  }];
  </code></pre>
  
  <p>Anyone an idea how to create a script for this?</p>