Skip to content

Instantly share code, notes, and snippets.

@sofish
Created August 7, 2013 03:21
Show Gist options
  • Save sofish/6170911 to your computer and use it in GitHub Desktop.
Save sofish/6170911 to your computer and use it in GitHub Desktop.

Revisions

  1. sofish created this gist Aug 7, 2013.
    12 changes: 12 additions & 0 deletions sort.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    // firefox 和 chrome 是 [1024, 6, 5, 3, 2, 1]
    // safari 中顺序没变
    [1,3,2,5,6,1024].sort(function(a, b) {
    return b > a;
    });


    // 在各中浏览器工作一致的方法
    // 用正负和零来排序,而不是 true/false
    [1,3,2,5,6,1024].sort(function(a, b) {
    return b - a;
    });