<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Shankarr's Weblog</title><link>http://blogs.msdn.com/shankak/default.aspx</link><description>Virtual Earth, AJAX, javascript, CSS.... let's talk about it....</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Sort overrides in javascript</title><link>http://blogs.msdn.com/shankak/archive/2006/08/18/sort-overrides-in-javascript.aspx</link><pubDate>Sat, 19 Aug 2006 03:09:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:706805</guid><dc:creator>Shankarr Kalyanaraaman</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shankak/comments/706805.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shankak/commentrss.aspx?PostID=706805</wfw:commentRss><wfw:comment>http://blogs.msdn.com/shankak/rsscomments.aspx?PostID=706805</wfw:comment><description>&lt;p&gt;For many a transition between languages with wonderful organization and amazing features to JavaScript which is language where you have lesser control over your code and memory and not as much sophistication is a harder experience. If "harder" is a strong word, the best may be "not a fuzzy feeling" as my codeveloper goes...&lt;/p&gt; &lt;p&gt;So, that being said, I have started to love this language, here is one of my first articles about this interesting language, which has essentially started to conquer the web....&lt;/p&gt; &lt;p&gt;Alright...prologue's over..to the coding&amp;nbsp;zone now...&lt;/p&gt; &lt;p&gt;So, I know people have been using the sort function which comes handy with the array data type in javascript. But, here is the true power which javascript gives us. &lt;/p&gt; &lt;p&gt;overrides on the sort functionality!. Atleast I know for sure dotnet gives us the ability to have IComparers which need to be written when implementing Sort on custom data structures.&amp;nbsp; In similar lines javascript allows function to be passed which returns the results of comparison and using a vary proprietary logic for comparing two elements.&lt;br&gt;&lt;/p&gt; &lt;p&gt;//Code start&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;pre&gt;function SortArray(unsortedArray, IComparerInstance)
{
 function ctor()
 {
  SortArray.refCount += 1;
  SortArray.steps = 0;
  doSort();
 }
 
 function doSort()
 {
  if(typeof unsortedArray == "object" &amp;amp;&amp;amp; 
	unsortedArray &amp;amp;&amp;amp; 
	unsortedArray.constructor == Array)
  {
   if(typeof IComparerInstance == "function")
   {
    unsortedArray.sort(IComparerInstance);
   }
   else
   {
    unsortedArray.sort();
   }
   
   document.write(ArrayToString(unsortedArray) + '&lt;br&gt;');
  }
 }
 
 ctor(); 
}

SortArray.refCount = 0;
SortArray.steps = 0;

function ArrayToString(inArray)
{
 if(typeof inArray == "object" &amp;amp;&amp;amp; 
	inArray &amp;amp;&amp;amp; 
	inArray.constructor == Array)
 {
  var cStr = "";
  for(var i = 0; i &amp;lt; inArray.length; i++)
  {
   cStr += i + " : " + inArray[i] + " ";
  }
  return cStr;
 }
 else
 {
  return null;
 }
}

function SortByStringLength (str1, str2)
{
 if(typeof str1 != "string" || typeof str2 != "string")
 {
  throw('one of the arguments is not a valid type');
 }
 
 var l1 = str1.length;
 var l2 = str2.length;
 
 SortArray.steps += 1;
 
 return (str2.length - str1.length);
}

function init()
{
 var main = [	'apple', 'orange', 'banana', 
		'papaya', 'jackfruit', 'honeydew', 
		'watermelon', 'strawberry', 'grape', 
		'lychee', 'tangerine', 'lemon', 
		'lime'
	    ];
 SortArray(main, SortByStringLength);
 
 //alerts section
 alert(SortArray.refCount);
};

var resultEl = document.getElementById('results');

init();&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;//Code end&lt;/p&gt;
&lt;p&gt;If you closely observe the code above, it has various features. The SortArray function is like a class with constructors (private || sealed) and the init function passes a function pointer which is called every time the array's sort method compares two elements. If you actually paste this code to a simple html file in a script tag, you can see that the strings inside the array are sorted in order of their length. Also note the comment which indicates&amp;nbsp;changing of sort order from ascending to descending and vice versa.&lt;/p&gt;
&lt;p&gt;I am going to stop this post right here and not bore all of you readers with contents that are pages long. So more on this in my next post....till then&lt;/p&gt;
&lt;p&gt;- Shankarr&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=706805" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shankak/archive/tags/javascript/default.aspx">javascript</category><category domain="http://blogs.msdn.com/shankak/archive/tags/sorting/default.aspx">sorting</category><category domain="http://blogs.msdn.com/shankak/archive/tags/overrides/default.aspx">overrides</category></item><item><title>This is a test post using Windows Live Writer</title><link>http://blogs.msdn.com/shankak/archive/2006/08/17/705329.aspx</link><pubDate>Fri, 18 Aug 2006 07:46:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:705329</guid><dc:creator>Shankarr Kalyanaraaman</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shankak/comments/705329.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shankak/commentrss.aspx?PostID=705329</wfw:commentRss><wfw:comment>http://blogs.msdn.com/shankak/rsscomments.aspx?PostID=705329</wfw:comment><description>&lt;p&gt;This is really cool... I mean slick. Check out the recently released windows live writer beta. You do not have to log on to the website (it stores the credentials for you and all you have to do to post a blog entry open your live writer and put your content and click publish....&lt;/p&gt; &lt;p&gt;how cool is that ? experience it...&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=705329" width="1" height="1"&gt;</description></item><item><title>Check out local.live.com today !!!</title><link>http://blogs.msdn.com/shankak/archive/2006/05/24/check-out-local-live-com-today.aspx</link><pubDate>Wed, 24 May 2006 11:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:605728</guid><dc:creator>Shankarr Kalyanaraaman</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shankak/comments/605728.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shankak/commentrss.aspx?PostID=605728</wfw:commentRss><wfw:comment>http://blogs.msdn.com/shankak/rsscomments.aspx?PostID=605728</wfw:comment><description>&lt;P&gt;&lt;FONT face=Garamond&gt;As one of the developers behind local.live.com (specifically the collections feature) , it is such a great pleasure for me to spread the word about the new &lt;A href="http://local.live.com/"&gt;local.live.com&lt;/A&gt;. There is a great deal of new stuff in it this time.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Garamond&gt;We have a completely new look and feel for the system and amazing features like the &lt;STRONG&gt;Collections, Traffic, a brand new Driving directions etc.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Garamond&gt;What more ? check out&amp;nbsp;&lt;/FONT&gt;&lt;A href="http://www.passthepoi.com/"&gt;&lt;FONT face=Garamond&gt;www.passthepoi.com&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Garamond&gt;. You can create great collections and make them public and post it on &lt;/FONT&gt;&lt;A href="http://www.passthepoi.com/"&gt;&lt;FONT face=Garamond&gt;www.passthepoi.com&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Garamond&gt;&amp;nbsp;and be a part of the wave.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Garamond&gt;Also check out &lt;A href="http://blogs.msdn.com/chota"&gt;http://blogs.msdn.com/chota&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Garamond&gt;Check it out....enjoy !!!&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=605728" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shankak/archive/tags/VE/default.aspx">VE</category><category domain="http://blogs.msdn.com/shankak/archive/tags/local.live.com/default.aspx">local.live.com</category><category domain="http://blogs.msdn.com/shankak/archive/tags/Virtual+Earth/default.aspx">Virtual Earth</category></item></channel></rss>