Sorting array by even and odd numbers
<p>Using javascript <code>sort()</code> method, I am trying to do sorting a list but sorting have in a group of even numbers and odd numbers.</p>

<p>The code which I tried is working fine with small list but if the list becomes big its not getting me proper result. Here is my code.</p>

<pre><code>var n = [10,20,21,4,5,6,7,99,0,12,13];
//var n = [10,20,0,12];
n.sort(function(a,b){
 if (a % 2 !=b % 2 ){
   return a%2;
  }else {
    return a - b; 
  }
});
</code></pre>

<p>The above code gives me as per accepted result like this 
Ans - <code>[0, 4, 6, 10, 12, 20, 5, 7, 13, 21, 99]</code> and the second Ans is:- <code>[0, 10, 12, 20]</code> </p>

<p>Working fine with this lists but if I changed into this </p>

<pre><code>var n = [10,20,21,4,5,6,7,99,0,12,13,10,20,21,4,5,6,7,99,0,12,13,10,20,21,4,5,6,7,99,0,12,13,10,20,21,4,5,6,7,99,0,12,13];
</code></pre>

<p>But in this case the result is something like this which is not proper.</p>

<p>Giving me Ans like this </p>

<p><code>[0, 0, 0, 0, 4, 4, 4, 4, 6, 6, 6, 6, 10, 10, 10, 10, 12, 5, 12, 5, 12, 5, 20, 20, 20, 20, 5, 12, 7, 7, 7, 7, 13, 13, 13, 13, 21, 21, 21, 21, 99, 99, 99, 99]</code> its a mixing of odd and even numbers.</p>

<p>Its giving me not proper result. Any suggestion. </p>
