473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sort() issue in Safari

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

Oct 10 '07 #1
5 2248
Liam wrote:
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
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Oct 10 '07 #2
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

On Oct 10, 12:23 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Liam wrote:
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
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>

Oct 10 '07 #3
Just tried the function yuo supplied. Works perfectly!

Thanks again.

Liam

Oct 10 '07 #4
In comp.lang.javascript message <11*********************@57g2000hsv.goog
legroups.com>, Wed, 10 Oct 2007 14:15:15, Liam <ne*********@gmail.com>
posted:
>
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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Oct 10 '07 #5
On Oct 11, 12:15 am, Liam <neptune6...@gmail.comwrote:
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.
--
Rob

Oct 10 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Greg Ercolano | last post by:
I'm trying to make a SELECT form that contains monospaced text where the headings and columns in the text align. Here's the HTML I've been using that seems to work on all browsers /except/...
5
by: sanj | last post by:
Hi all, My site is located at: http://www.eastdayspa.com/index.html I have use these main styles /* main styles */
3
by: Marcia Gulesian | last post by:
The following code suppresses the 'enter' key, when run in I.E. 5.5 or later (Windows) but not when run in Safari (Mac) <body onkeypress="javascript:keysuppress(event)" > function...
2
by: Marcia Gulesian | last post by:
The following code suppresses the 'enter' key, when run in I.E. 5.5 or later (Windows) but not when run in Safari (Mac) <body onkeypress="javascript:keysuppress(event)" > function...
4
by: jeffsal | last post by:
I am using sorttable.js to sort a table which works fine which allows a user to sort the table by clicking on the column header. Is there some code I could add to the page (onload or something) to...
8
by: bissatch | last post by:
Hi, I am about to create a table, where the values are taken from an XML file, where each column header you can click and it will sort the table rows at the client side. I have got to the...
5
techtherapy
by: techtherapy | last post by:
Hello all, This ones a little different as I'm using some flash actionscript to control the swaping. The following page uses a hideDiv, ShowDiv Javascript that is working flawlessly in...
15
by: GinnTech | last post by:
I have a site that works perfectly in IE6 IE7 FF2 FF3 but not in the latest Safari. Here is the issue. I am attempting to call functions within a flash object. When trying to attempt to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.