title: Display Top Three Items in a List by Data Attribute
body: <p>I have a list that is sorted by JS using data attributes. The list appears like this: </p>
  
  <pre><code>&lt;li data-sortm="4"&gt;Migraines&lt;/li&gt;
  &lt;li data-sortm="2"&gt;Stress&lt;/li&gt;
  &lt;li data-sortm="2"&gt;Depression&lt;/li&gt;
  &lt;li data-sortm="1"&gt;Anxiety&lt;/li&gt;
  &lt;li data-sortm="1"&gt;Lack of Appetite&lt;/li&gt;
  &lt;li data-sortm="1"&gt;Muscle Spasms&lt;/li&gt;
  &lt;li data-sortm="0"&gt;Nausea&lt;/li&gt;
  &lt;li data-sortm="0"&gt;Insomnia&lt;/li&gt;
  &lt;li data-sortm="0"&gt;Pain&lt;/li&gt;
  &lt;li data-sortm="0"&gt;PMS&lt;/li&gt;
  &lt;li data-sortm="0"&gt;Seizures&lt;/li&gt;
  &lt;li data-sortm="0"&gt;Fatigue&lt;/li&gt;
  </code></pre>
  
  <p>What I would like to do is display the top three items and hide or remove the rest of the list. For example in the list above the top three would look like this: </p>
  
  <pre><code>&lt;li data-sortm="4"&gt;Migraines&lt;/li&gt;
  &lt;li data-sortm="2"&gt;Stress&lt;/li&gt;
  &lt;li data-sortm="2"&gt;Depression&lt;/li&gt;
  </code></pre>
  
  <p>There is one catch, while I would like the top three displayed if we have a setup like this: </p>
  
  <pre><code>&lt;li data-sortm="4"&gt;Migraines&lt;/li&gt;
  &lt;li data-sortm="3"&gt;Pain&lt;/li&gt;
  &lt;li data-sortm="2"&gt;Stress&lt;/li&gt;
  &lt;li data-sortm="2"&gt;Depression&lt;/li&gt;
  </code></pre>
  
  <p>I would want to show all four since the last two are the same number. </p>
  
  <p>How do I do this using jQuery? </p>
  
  <p>I have considered using RegEx as I think that may be a way but RegEx is not an area I find easy to use.</p>
  
  <p>Here is the code I am using to sort the list: </p>
  
  <pre><code>$(".medical-list li").sort(sort_li_medical).appendTo('.medical-list');
    function sort_li_medical(a, b){
      return ($(a).data('sortm')) &lt; ($(b).data('sortm')) ? 1 : -1;    
  }
  </code></pre>
  
  <p>Note: I am using v2.1 of jQuery.</p>