数组排序的全能方法

  有的时候我们可以对字母,数字,字符串中的时间,进行排序,但正常情况下数组只能对数字进行排序,无法满足我们的要求,所以封装了一个全能的方法

  sort(function(a,b){

    return a-b

    })        仅仅是对数字的从小到大排序;

  还有一种全能的方法,可以对任何东西排序;

  function getsort(a,b){

    if(a>b){

      return 1

    }

    else if(a==b){

      return 0;

    }

    else{

      return  -1

    }

  这是从小到大排序,如果从大到小排序 1和-1;换下位置;

  拿走!拿走!别客气!

原文地址:https://www.cnblogs.com/shangjun6/p/10268536.html