Skip to content

Instantly share code, notes, and snippets.

@gindis
Forked from sofish/sort.js
Created October 7, 2015 03:48
Show Gist options
  • Select an option

  • Save gindis/b49e1ec822011ecf8de1 to your computer and use it in GitHub Desktop.

Select an option

Save gindis/b49e1ec822011ecf8de1 to your computer and use it in GitHub Desktop.
safari 不能用 true / false 来做排序
// 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;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment