冒泡排序
const mySort = function(callback) {
for(let i=0 ; i< this.length-1; i++){
for(let j=0; j < this.length - i ; j++){
if(callback(this[j],this[j+1]) > 0){
let temp = this[j];
this[j] = this[j+1];
this[j+1] = temp;
}
}
}
return this;
}
Array.prototype.mySort = mySort;
const arr = [5,3,1,2,4,6]
//正序:(a,b) => a - b)
//逆序:(a,b) => b - a)
console.log(arr.mySort((a,b) => a-b));