sort() issue in Safari

L

Liam

Hi all. New to the group and new to using Safari (for work).

I noticed while coding a module at work that the sort() works quite
differently in Safari than it does in FireFox and IE.

My issue is that an array ["red","r","rad"] should look like
["r","rad","red"] after running it through the sort() function. In FF
and IE it does, but in Safari (and I assume in Konqueror, as well) it
looks like ["rad","red","r"] after the sort().

Any suggestions are greatly appreciated.

Thanks,

Liam
 
T

Thomas 'PointedEars' Lahn

Liam said:
I noticed while coding a module at work that the sort() works quite
differently in Safari than it does in FireFox and IE.

My issue is that an array ["red","r","rad"] should look like
["r","rad","red"] after running it through the sort() function. In FF
and IE it does, but in Safari (and I assume in Konqueror, as well)

You assume a connection where hardly one exists. Apple's JavaScriptCore is
merely a fork of KJS, as WebCore is a fork of KHTML 3.0.2 (current version
is 3.5). It remains to be seem whether changes made in JavaScriptCore or
WebCore are actually backported to KJS or KHTML.
it looks like ["rad","red","r"] after the sort().

That would be a Safari bug, or at least a peculiarity. Are you testing with
a Safari beta (for Windows) by any chance?
Any suggestions are greatly appreciated.

1. Don't test with Safari betas.
2. You can *try* to work around the bug by passing a comparator reference:

function dictComp(s1, s2)
{
return ((s1 < s2) ? -1 : ((s1 > s2) ? 1 : 0));
}

["red", "r", "rad"].sort(dictComp);


PointedEars
 
N

neptune6jun44

Thanks for the tip...

Safari vers. is 2.0.4(419.3), Mac OS X.

I'll give your function a try in a bit.

Thanks again.

Liam

Liam said:
I noticed while coding a module at work that the sort() works quite
differently in Safari than it does in FireFox and IE.
My issue is that an array ["red","r","rad"] should look like
["r","rad","red"] after running it through the sort() function. In FF
and IE it does, but in Safari (and I assume in Konqueror, as well)

You assume a connection where hardly one exists. Apple's JavaScriptCore is
merely a fork of KJS, as WebCore is a fork of KHTML 3.0.2 (current version
is 3.5). It remains to be seem whether changes made in JavaScriptCore or
WebCore are actually backported to KJS or KHTML.
it looks like ["rad","red","r"] after the sort().

That would be a Safari bug, or at least a peculiarity. Are you testing with
a Safari beta (for Windows) by any chance?
Any suggestions are greatly appreciated.

1. Don't test with Safari betas.
2. You can *try* to work around the bug by passing a comparator reference:

function dictComp(s1, s2)
{
return ((s1 < s2) ? -1 : ((s1 > s2) ? 1 : 0));
}

["red", "r", "rad"].sort(dictComp);

PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
My issue is that an array ["red","r","rad"] should look like
["r","rad","red"] after running it through the sort() function. In FF
and IE it does, but in Safari (and I assume in Konqueror, as well) it
looks like ["rad","red","r"] after the sort().

From my recent reading of ISO/IEC 16262 (see articles "searching an
array..."), I can assert that, from what you say, Safari sorts
incorrectly.

That is, provided that the example strings contain one or three
characters each.

If they have on the end an invisible terminating character, at a code
point higher than any other character used, then that's wrong but the
sort is right.
 
R

RobG

Hi all. New to the group and new to using Safari (for work).

I noticed while coding a module at work that the sort() works quite
differently in Safari than it does in FireFox and IE.

Which version of Safari?

My issue is that an array ["red","r","rad"] should look like
["r","rad","red"] after running it through the sort() function. In FF
and IE it does, but in Safari (and I assume in Konqueror, as well) it
looks like ["rad","red","r"] after the sort().

Safari 3 on Mac OS conforms to what you get from Firefox and IE.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top