<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Sort numbers in Javascript array</title>
	<atom:link href="http://www.zparacha.com/sort_numeric_arrays/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zparacha.com/sort_numeric_arrays/</link>
	<description>Effective programming and blogging tips by Zaheer Paracha</description>
	<lastBuildDate>Sat, 11 Feb 2012 03:00:48 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: javascript coders-please help - DesignersTalk</title>
		<link>http://www.zparacha.com/sort_numeric_arrays/comment-page-1/#comment-1674</link>
		<dc:creator>javascript coders-please help - DesignersTalk</dc:creator>
		<pubDate>Wed, 14 Sep 2011 16:25:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.zparacha.com/sort_numeric_arrays/#comment-1674</guid>
		<description>[...] Google is your friend  second thing I found when I searched sorting numbers in javascript was this: Sort numbers in Javascript array [...]</description>
		<content:encoded><![CDATA[<p>[...] Google is your friend  second thing I found when I searched sorting numbers in javascript was this: Sort numbers in Javascript array [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ZQ</title>
		<link>http://www.zparacha.com/sort_numeric_arrays/comment-page-1/#comment-1238</link>
		<dc:creator>ZQ</dc:creator>
		<pubDate>Tue, 21 Dec 2010 22:27:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.zparacha.com/sort_numeric_arrays/#comment-1238</guid>
		<description>I believe this post is incorrect.  The explanation above should read...

- for a positive value (a number greater than 0), ‘b’ will be put before ‘a’.
- for a negative value (a number less than 0), ‘a’ will be put before ‘b’.
- for 0 (meaning ‘a’ and ‘b’ are equal), then the positions of these two elements will not change in the sorted array

ZQ</description>
		<content:encoded><![CDATA[<p>I believe this post is incorrect.  The explanation above should read&#8230;</p>
<p>- for a positive value (a number greater than 0), ‘b’ will be put before ‘a’.<br />
- for a negative value (a number less than 0), ‘a’ will be put before ‘b’.<br />
- for 0 (meaning ‘a’ and ‘b’ are equal), then the positions of these two elements will not change in the sorted array</p>
<p>ZQ</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Larry Battle</title>
		<link>http://www.zparacha.com/sort_numeric_arrays/comment-page-1/#comment-1184</link>
		<dc:creator>Larry Battle</dc:creator>
		<pubDate>Sun, 10 Oct 2010 20:28:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.zparacha.com/sort_numeric_arrays/#comment-1184</guid>
		<description>Fastest way to sort numbers in javascript.
Here&#039;s my code.
&lt;code&gt;

function insertionSort3 (sortMe){
	var Len = sortMe.length, i = -1, j, tmp;
	
   while( Len-- ){
      tmp = sortMe[++i];
	  j = i;
	  while( j-- &amp;&amp; sortMe[j] &gt; tmp ) {
         sortMe[j+1]=sortMe[j];
      }
      sortMe[j+1]=tmp;
   }
}
&lt;/code&gt;

Here&#039;s a test. You need to use Firefox and Firebug to see the results.
&lt;code&gt;

var arr = [];

var getArrOfRandomNumbers = function( howMany, largestValue ){
	var arr = [];
	howMany = ( howMany &gt; 0 ) ? howMany : 0;
	while( howMany-- ){
		arr.push( Math.floor( Math.random() * largestValue ));
	}
    return arr;
};

arr = getArrOfRandomNumbers( 1000, 110 );

console.time( &quot;insertionSort&quot; );
insertionSort3( arr );
console.timeEnd( &quot;insertionSort&quot; );


arr = getArrOfRandomNumbers( 1000, 110 );

console.time( &quot;arr.sort()&quot; );
arr = arr.sort( function(a,b){return a-b;});
console.timeEnd( &quot;arr.sort()&quot; );

&lt;/code&gt;
-Larry Battle</description>
		<content:encoded><![CDATA[<p>Fastest way to sort numbers in javascript.<br />
Here&#8217;s my code.<br />
<code></p>
<p>function insertionSort3 (sortMe){<br />
	var Len = sortMe.length, i = -1, j, tmp;</p>
<p>   while( Len-- ){<br />
      tmp = sortMe[++i];<br />
	  j = i;<br />
	  while( j-- &amp;&amp; sortMe[j] &gt; tmp ) {<br />
         sortMe[j+1]=sortMe[j];<br />
      }<br />
      sortMe[j+1]=tmp;<br />
   }<br />
}<br />
</code></p>
<p>Here&#8217;s a test. You need to use Firefox and Firebug to see the results.<br />
<code></p>
<p>var arr = [];</p>
<p>var getArrOfRandomNumbers = function( howMany, largestValue ){<br />
	var arr = [];<br />
	howMany = ( howMany &gt; 0 ) ? howMany : 0;<br />
	while( howMany-- ){<br />
		arr.push( Math.floor( Math.random() * largestValue ));<br />
	}<br />
    return arr;<br />
};</p>
<p>arr = getArrOfRandomNumbers( 1000, 110 );</p>
<p>console.time( "insertionSort" );<br />
insertionSort3( arr );<br />
console.timeEnd( "insertionSort" );</p>
<p>arr = getArrOfRandomNumbers( 1000, 110 );</p>
<p>console.time( "arr.sort()" );<br />
arr = arr.sort( function(a,b){return a-b;});<br />
console.timeEnd( "arr.sort()" );</p>
<p></code><br />
-Larry Battle</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bighippo</title>
		<link>http://www.zparacha.com/sort_numeric_arrays/comment-page-1/#comment-272</link>
		<dc:creator>bighippo</dc:creator>
		<pubDate>Fri, 03 Oct 2008 03:48:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.zparacha.com/sort_numeric_arrays/#comment-272</guid>
		<description>whoa thanks!  bighelp!</description>
		<content:encoded><![CDATA[<p>whoa thanks!  bighelp!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

