jQuery javascript custom sort procedure works in Firefox, but IE doesn't seem to get it… (copy-paste example code)

后端 未结 1 1954
北海茫月
北海茫月 2020-12-06 17:11

i\'ve built this sample code based on a real problem I have in an application. I\'ve got a custom sort procedure to sort jQuery arrays. A container contains a list of items

相关标签:
1条回答
  • 2020-12-06 17:25

    Your sort procedure is subtly wrong: you need to account for equalities as well, and boolean is not the correct return type (see addendum).

    Do this:

    return value1 - value2;
    

    instead of:

    return value1 > value2;
    

    Addendum:

    The general form of a sort comparison function f(A,B) needs to return > 0 if A > B, < 0 if A < B, and 0 if no alteration needs to occur. Returning a boolean gets you caught by falsey values not representing what you think they do.

    0 讨论(0)
提交回复
热议问题