var a = [11,2,3,4,5,7,8,4,33,2,6]; Array.prototype.sorts = function(){ var $this = this, i=1, arrays = $this.sort(function(a,b){return (a-b)>0}), len = arrays.length; if(len<2) return arrays; while(i < len){ if(arrays[i] == arrays[i-1]){ len--; arrays.splice(i,1); }else{ i++; } } return arrays; } a.sorts();
初衷是尽可能的减少循环次数。