1 //基本数组去重
 2 ///输入:向数组中添加功能函数unique
 3 ///输出:返回一个没有重复元素的数组
 4 Array.prototype.unique = function(){
 5     result =[];
 6     this.forEach(function(x){
 7         if(result.indexOf(x) < 0)
 8             result.push(x);
 9     });
10     return result;
11 };
12 
13 //数字和字符串数组的排序
14 ///输入:向数组中添加功能函数ssort
15 ///输出:返回一个从小到达的排序结果,数字在前,字符串在后
16 ///注意事项:只针对含有数字和字符串的数组
17 var shuzu =[11,'s',234,'a',2,'d',5];
18 
19 Array.prototype.ssort = function(){
20     resultA = [];
21     resultB = [];
22     resultA = this.filter(function(x){
23         if(typeof x === 'string')
24             return true;
25     });
26     resultB = this.filter(function(x){
27         if(typeof x === 'number')
28             return true;
29     });
30     resultA.sort();
31     resultB.sort(function(a,b){
32         return a-b;
33     });
34     this.length = 0;
35     return this.concat(resultB,resultA);
36 };
排序

相关文章:

  • 2021-05-19
  • 2018-09-25
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
猜你喜欢
  • 2021-10-19
  • 2021-10-05
  • 2021-12-09
相关资源
相似解决方案