title: Ruby sort by multiple fields and multilple directions for different data types
body: <p>I need to write a <code>multi_sort</code> method to sort an array of hash which accepts a hash as an argument, eg: { a_sort: 1, display_sort: 1 }. This hash is sort fields and sort direction. (1 means ascending, -1 means descending).</p>
  
  <pre><code>items = [ {name: 'Album 1', a_sort: 5, display_sort: 3}, 
            {name: 'Album 2', a_sort: 1, display_sort: 5}, 
            {name: 'Album 3', a_sort: 3, display_sort: 2},
            {name: 'Album 5', a_sort: 1, display_sort: 8}, 
            {name: 'Album 7', a_sort: 5, display_sort: 1}, 
            {name: 'Album 7', a_sort: 5, display_sort: 6} ]
  
  multi_sort(items, {a_sort: 1, display_sort: 1})
  </code></pre>
  
  <p>I can't figure it out after 3 hours. The expected output is the array that is sorted correctly.</p>
  
  <pre><code>      [ {name: 'Album 2', a_sort: 1, display_sort: 5},
          {name: 'Album 5', a_sort: 1, display_sort: 8},
          {name: 'Album 3', a_sort: 3, display_sort: 2},
          {name: 'Album 7', a_sort: 5, display_sort: 1}
          {name: 'Album 1', a_sort: 5, display_sort: 3}, 
          {name: 'Album 7', a_sort: 5, display_sort: 6} ]
  </code></pre>