title: javascript sort and sort equals on result. how?
body: <p>I have a problem sorting objects of structure {"name", "count"}:</p>
  
  <pre><code>1. name =&gt; "aaa", count =&gt; 1
  2. name =&gt; "bbb", count =&gt; 2
  3. name =&gt; "ccc", count =&gt; 3
  4. name =&gt; "ddd", count =&gt; 1
  5. name =&gt; "eee", count =&gt; 1
  </code></pre>
  
  <p>I need to sort this on "count" (small to big, then big to small).</p>
  
  <p>My sort function:</p>
  
  <pre><code>mass.sort(compareElements);
  
  function compareElements(a, b)
  {
   if(a &lt; b) return -1;
   else if(a &gt; b) return 1;
   else return 0;
  }
  </code></pre>
  
  <p>On first call (small to big) I get one result 'res1'<br />
  on second call (big to small) I get result 'res2'<br />
  on third call (small to big again) I get 'res3' !== 'res1' !!</p>
  
  <p>The order of the elements in res1 and res3 is not the same. I need them to be the same.</p>