标签:res 重排序 排序 log push 数组去重 turn unique index
1 var c = [1,8,6,4,88,22,99,4,6,86,5,58,89,5]; 2 c.sort(function (a,b) { 3 return a - b; 4 }); 5 c = unique(c); 6 function unique(arr){ 7 var res = []; 8 for(var i = 0;i < arr.length;i++){ 9 if(res.indexOf(arr[i]) == -1) 10 res.push(arr[i]) 11 } 12 return res; 13 };
简化版
1 var c = [1,8,6,4,88,22,99,4,6,86,5,58,89,5]; 2 c = unique(c); 3 c.sort(function (a,b) { 4 return a - b; 5 }); 6 function unique(arr){ 7 var res = []; 8 for(var i = 0;i < arr.length;i++) 9 res.indexOf(arr[i]) == -1 && res.push(arr[i]); 10 return res; 11 };
标签:res 重排序 排序 log push 数组去重 turn unique index
原文地址:http://www.cnblogs.com/-maomao-/p/7677726.html