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 8257897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:21:26+00:00 2026-06-08T02:21:26+00:00

In this environment, I only have access to intrinsic Javascript functions, so cannot load

  • 0

In this environment, I only have access to intrinsic Javascript functions, so cannot load external libraries.

When trying to sort by 3 keys, inner, middle, and outer, only my last sort seems to be preserved.

function Claim(claimNumber, lastName, claimStatus, record)
{
    this.claimNumber = claimNumber;
    this.lastName = lastName;
    this.claimStatus = claimStatus;
    this.record = record;
}
function sortLastName(a, b) { 
    var o1 = a["lastName"].toUpperCase(); 
    var o2 = b["lastName"].toUpperCase(); 
    if (o1 < o2) return -1; 
    if (o1 > o2) return 1; 
    return 0; 
} 
function sortClaimNumber(a, b) { 
    var o1 = a["claimNumber"].toUpperCase(); 
    var o2 = b["claimNumber"].toUpperCase(); 
    if (o1 < o2) return -1; 
    if (o1 > o2) return 1; 
    return 0; 
} 
function sortClaimStatus(a, b) { 
    var o1 = ("00" + a["claimStatus"].toUpperCase()).substr(-2); 
    var o2 = ("00" + b["claimStatus"].toUpperCase()).substr(-2); 
    if (o1 < o2) return 1; 
    if (o1 > o2) return -1; 
    return 0; 
} 
var claimListArray = buildClaimList(record);
claimListArray.sort(sortClaimStatus);
claimListArray.sort(sortClaimNumber);
claimListArray.sort(sortLastName);

The output should look like (lastname asc, claimnumber asc, claimstatus desc):

AARDVARK   111222A    15
AARDVARK   111222A    6
AARDVARK   111222A    1
AARDVARK   222555C    8
AARDVARK   222555C    4
BANKS      123132Z    78

but instead looks like:

AARDVARK   111222A    15
AARDVARK   222555C    4
AARDVARK   111222A    1
AARDVARK   222555C    8
AARDVARK   111222A    6
BANKS      123132Z    78

That is to say, only the lastName sort is preserved, as if the first two sorts did not happen.
Is there something about arrays and sorting that I’m missing that ignores previous sorts?

Is there a better approach?

  • 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-06-08T02:21:29+00:00Added an answer on June 8, 2026 at 2:21 am

    try like this

    function comp(a, b){
        var ret = sortLastName(a, b);
        if(ret != 0){
            return ret;
        }           
        ret = sortClaimNumber(a, b);
        if(ret != 0){
            return ret;
        }
    
        return sortClaimStatus(a, b);
    }
    claimListArray.sort(comp);
    

    EDIT (by Malvolio):

    Sorry to be editing your post but this solution, although technically correct, is bad Javascript. Write it like this:

    claimListArray.sort(function(a, b) {
        return sortLastName(a, b)
            || sortClaimNumber(a, b)
            || sortClaimStatus(a, b);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you update this environment variable at runtime so that ctypes can load
I have following this blog in setting Xvfb in my ubuntu environment: http://corpocrat.com/2008/08/19/how-to-install-xvfb-x11-server-in-linux-server/ So
I have a label and this code: string User = Environment.UserName; toolStripStatusLabel1.Text = This
ENVIRONMENT: C# I have a table of equivalent values, like this: CHEVR = CHEVROLET
The scenario I have access to this old linux server, that no longer receives
Consider this scenario. I have a small enterprise project dev environment. We use archiva
I now have my Windows Azure environment set up so that I can access
I have a large site w/ magento and wordpress. The only access I have
If I set this in my environment config.action_controller.cache_store = :mem_cache_store ActionController::Base.cache_store will use a
When I run my rails console I got something like this: Loading development environment

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.