//方法1冒泡排序
var mySort = function(fn){
if(typeof fn != 'function'){
fn = function(a,b){
return a-b;
}
}
for(var i=0; i < this.length-1;i++){
for(var j=i+1;j<this.length;j++){
var t = this[i];
if(fn(this[i],this[j]) > 0){
this[i] = this[j];
this[j] = t;
}
}
}
return this;
}
if(typeof Array.prototype.sorts!= 'fucntion'){
Array.prototype.sorts = mySort;
mySort = null;
}
//方法2 插入排序
var mySort = function(fn){
if(typeof fn != 'function'){
fn = function(a,b){
return a-b;
}
}
for(var i=1;i<this.length;i++){
//var t = this[i-1];
var t = this[i];
var j = i-1;
while(j >= 0 && fn(this[j],t)> 0 ){
this[j+1] = this[j];
j--;
}
this[j+1] = t;
}
return this;
}
if(typeof Array.prototype.sorts!= 'fucntion'){
Array.prototype.sorts = mySort;
mySort = null;
}