JavaScript Collation Fail

In JavaScript, the localeCompare method on Strings seems like a great way to properly sort strings, but its not:
localeCompare Javasript method in 4 browsers
Hint: The last line should all look the same. At least I expect Firefox and Opera to agree. You can’t expect much from IE6.

For kicks try out other browsers and post the final sorted list in the comments (hopefully my blog supports unicode).

Tags: , , , , , ,

5 Responses to “JavaScript Collation Fail”

  1. A.Fruit Says:

    Here it is in Safari 3 / Webkit:

  2. A.Fruit Says:

    Doh.

    Html got Stripped. Here’s the link to the image:

    http://idisk.mac.com/afruit-Public/safari-js-test.png

  3. Michael Schurter Says:

    Just testing out copying and pasting from the test page:

    a,A,ä,æ,q,R,z,Z

    Hm… Safari and Firefox agree. Wonder what IE7 & 8 have to say… I guess IE6 is pretty close to Safari and FF. Seems Opera is the only one completely crazy.

  4. A.Fruit Says:

    I’ve been noticing Firefox 3 being closer to Safari, then Firefox 3 is to Firefox 2 –specifically with CSS rendering and stuff. (Which doesn’t have much to do with JS, but it’s just a general thing I’ve observed)

    Webkit advocates do rave about the new JavaScript engine called “Squirrelfish”.

    http://webkit.org/blog/189/announcing-squirrelfish/

    Which brings a reminder about the Dr. Moreau conversations we’ve had.

  5. a girl Says:

    IE7: string_list.sort(localesort): a,A,ä,æ,q,R,z,Z

Leave a Reply