js 数组排序要注意的问题,返回的值最好为 -1, 0, 1之间的值

 

var test10Elements = [7, 6, 5, 4, 3, 2, 1, 0, 8, 9];
var comparefn = function (x, y) {
  return x - y;
};
test10Elements.sort(comparefn);

var comparefn2 = function (x, y) {
  return x > y;
};
test10Elements.sort(comparefn2);

 

http://w3help.org/zh-cn/causes/SJ9013

posted @ 2014-06-24 19:20  金帛  阅读(606)  评论(0编辑  收藏  举报