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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:38:12+00:00 2026-05-25T18:38:12+00:00

In IE 9, if I type this in the console: [1, 4, 2, 3].sort(function

  • 0

In IE 9, if I type this in the console:

[1, 4, 2, 3].sort(function (a, b) { return a < b; });

The resulting array is: [1, 4, 2, 3].

If I do this in FF/Chrome, I get it, reverse-sorted: [4, 3, 2, 1].

How come this doesn’t work in IE?

EDIT: Is there a function out there that abstracts these browser differences? In other words, is there a function I can pass function(a, b) { return a < b; } in and get the same result in all browsers? Any open-source stuff?

  • 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-25T18:38:13+00:00Added an answer on May 25, 2026 at 6:38 pm

    Maybe because the function is supposed to return -1 if a is smaller, 0 if they are equal, and 1 if a is larger (or vice versa if you want reverse order). Edit: In fact, it must be zero, a positive or negative number (as @pimvdb pointed out, and that’s what I make use of in the example below). Your function will never return -1 though and that might create problems.

    Consider 1 and 3. Your function returns 1 for 1 < 3, which is ok, but returns 0 for 3 < 1. In one case the number are different, in the other you are saying that they are equal.

    That FF/Chrome sort it in reverse order might be due to the sorting algorithm they are using.

    Try:

    [1, 4, 2, 3].sort(function (a, b) { return b - a; });
    

    Update: To substantiate this, we can have a look at the specification, Section 15.4.4.11 Array.prototype.sort(comparefn), where the properties are given which have to be fulfilled by a comparison function:

    A function comparefn is a consistent comparison function for a set of values S if all of the requirements below are met for all values a, b, and c (possibly the same value) in the set S: The notation a <CF b means comparefn(a,b) < 0; a =CF b means comparefn(a,b) = 0 (of either sign); and a >CF b means comparefn(a,b) > 0.

    • Calling comparefn(a,b) always returns the same value v when given a specific pair of values a and b as its two arguments. Furthermore, Type(v) is Number, and v is not NaN. Note that this implies that exactly one of a <CF b,
      a =CF b, and a >CF b will be true for a given pair of a and b.
    • Calling comparefn(a,b) does not modify the this object.
    • a =CF a (reflexivity)
    • If a =CF b, then b =CF a (symmetry)
    • If a =CF b and b =CF c, then a =CF c (transitivity of =CF)
    • If a <CF b and b <CF c, then a <CF c (transitivity of <CF)
    • If a >CF b and b >CF c, then a >CF c (transitivity of >CF)

    NOTE The above conditions are necessary and sufficient to ensure that comparefn divides the set S into equivalence classes and that these equivalence classes are totally ordered.

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

Sidebar

Related Questions

Code: Sorter.prototype.init_bubblesort = function(){ console.log(this.rect_array); this.end = this.rect_array.length; this.bubblesort(); } Sorter.prototype.init = function(array,sort_type){ this.rect_array
I have this piece of code: ['design','finish','grills'].each(function(type) { this.json.type.each(function(obj, index) { console.log(obj); }); }.bind(this));
See this code: var jsonString = '{id:714341252076979033,type:FUZZY}'; var jsonParsed = JSON.parse(jsonString); console.log(jsonString, jsonParsed); When
When I type this: puts 'repeat' * 3 I get: >> repeat repeat repeat
The type of this function is function :: Num a => ([Char],a) -> ([Char],a)
In Firefox 3.5, I type this in the Firebug console : false=={} // =>
<script type=text/javascript> $(document).ready(function() { jQuery.tablesorter.addParser({ id: commaDigit, is: function(s) { return false; }, format:
If I type this line in an MS-DOS command prompt window: ipy -X:ColorfulConsole IronPython
How to type this shortcut in emacs: C-c .|w
When I type this into the Visual Studio 2008 immediate window: ? .9 -

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.