//一维数组的排序
// type 参数 
// 0 字母顺序(默认) 
// 1 大小 比较适合数字数组排序
// 2 拼音 适合中文数组
// 3 乱序 有些时候要故意打乱顺序,呵呵
// 4 带搜索 str 为要搜索的字符串 匹配的元素排在前面
function Array.prototype.SortBy(type,str)

switch (type)

    case 0:this.sort(); break;
    case 1:this.sort(function(a,b){ return a-b; }); break;
    case 2:this.sort(function(a,b){ return a.localeCompare(b) }); break;
    case 3:this.sort(function(){ return Math.random()>0.5?-1:1; }); break;
    case 4:this.sort(function(a,b){ return a.indexOf(str)==-1?1:-1; }); break;
    default:this.sort();
   }
}

相关文章:

  • 2021-11-03
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2022-12-23
相关资源
相似解决方案