View Single Post
Old 02-28-2013, 11:07 PM   PM User | #15
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by Airblader View Post
@ rndme

1. True
2. Not entirely -- some sorting algorithms will compare an element to itself. Your sorting function should always support this case (which just using the difference does, of course).
what do you mean by "some sorting algorithms"?

im talking about

Code:
function srtStr(a,b){return a>b?1:-1;}
versus
Code:
function srtStr(a,b){return a>b?1:(b==a?0:-1);}
i also said "when sorting unique strings", which means that the difference is always NaN, unless you know something i don't...

after all, if the elements are unique, it's impossible for a proper sort function to return zero.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote