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 };