<script>
function MyArray() {
this.mySort=function () {
var max = null;
// console.log(arguments);
var array = arguments[0];
var sort =arguments[1]==='asc'? 'asc' :'desc';
for(var i=0; i<array.length-1;i++ ){
for(var j=0; j<array.length-1;j++){
//升序
if(sort==='asc'){
//当前 数 和 后一个数对比
if(array[j] > array[j+1]){
max=array[j]; //把较大的数赋值给max
array[j]=array[j+1];//较小的数丢到前面
array[j+1]=max;//较大的数丢到后面
}
//降序
}else{
//当前 数 和 后一个数对比
if(array[j] < array[j+1]){
max=array[j+1];
//较小的数丢到后面
array[j+1]=array[j];
//大的数丢到前面
array[j]=max;
}
}
}
}
return array;
}
this.myReverse=function () {
var newArray= new Array();
for(var i=0;i<=arguments[0].length-1;i++){
newArray[i]=arguments[0][arguments[0].length-(i+1)]
}
return newArray;
}
this.myMax=function(){
return this.mySort(arguments[0])[0]
}
this.myMin=function () {
return this.mySort(arguments[0])[arguments[0].length-1]
}
}
var arr = new MyArray();
var a= [90,5,4,10,9,8];
console.log(arr.myReverse(a));
console.log(arr.mySort(a,'asc'));
console.log(arr.mySort(a,'desc'));
console.log(arr.myMax(a));
console.log(arr.myMin(a));
</script>