Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6098213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:07:57+00:00 2026-05-23T13:07:57+00:00

I have been staring myself blind at this piece of javascript code, I need

  • 0

I have been staring myself blind at this piece of javascript code, I need some help.

It is a case insensitive sort function that will properly handle special (danish) characters, however it refuses to work in IE7 and I cannot see any reason why it should not work. It is not that fancy…

function _compare(a, b) {
    var sortorder = " 0123456789.abcdefghijklmnopqrstuvwxyzæøå",
        min = 0,
        idx = 0,
        c = 0;
    a = ' ' + a;
    b = ' ' + b;
    a = a.substring(1).toLowerCase();
    b = b.substring(1).toLowerCase();

    min = Math.min(a.length, b.length);

    while (idx < min && a[idx] == b[idx]) {
        idx++;
    }

    if (idx == min) {
        if (a.length > b.length) {
            c = 1;
        }
        else if (a.length < b.length) {
            c = -1;
        }
    }
    else {
        c = (sortorder.indexOf(a[idx]) > sortorder.indexOf(b[idx])) ? 1 : -1;
    }

    return c;
}

var key, ar = [];

ar.push("TEST");
ar.push("abcd");
ar.push("test");
ar.push("øæå!");
ar.push("oåø!");
ar.push("åæø!");
ar.push("aaø!");

ar.sort(_compare);

for (key in ar) {
    $("pre").append(ar[key] + "<br />");
}

http://jsfiddle.net/hpvek/ – it works as excepted in FF, Chrome, IE8-9 and Safari. IE7 (possible IE6, which I do not have in my testing arsenal) seems the odd man out.

thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:07:58+00:00Added an answer on May 23, 2026 at 1:07 pm
    for (key in ar) {
        $("pre").append(ar[key] + "<br />");
    }
    

    This is the wrong way to iterate over an array if you want to preserve the order.

    Though, it’s not the problem here it seems.

    Gosh, it was simple. IE doesn’t support treating strings like arrays. You have to convert them into arrays to lookup the idx index or use charAt.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Case Quite often I find myself staring at some old code that doesn't look
I don't consider myself a complete SQL novice, but I have been staring at
I have been trying to teach myself MEF, starting with this tutorial: http://blogs.msdn.com/b/brada/archive/2008/09/29/simple-introduction-to-composite-applications-with-the-managed-extensions-framework.aspx There
I have been starting to write some reasonably large and or confusing MySQL queries
I've been trying to get this to work. It's basically a way to have
I have been having some trouble figuring out how exactly I get a process's
I mainly code small programs for myself, but recently, I've been starting to code
This is my first post, have been a lurker for a long time, so
i have a input tag which is non editable, but some times i need
I'm just starting to teach myself Objective C and have been fooling around with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.