方法一:
function buble(arr){for(var i =0;i < arr.length;i++){for(var j = 0;j < arr.length;j++){if(arr[i] < arr[j]){var temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
return arr;
}
方法二:
[链接描述][1]
var arr = [1,3,20,5,2,9,6,4,80,9,4];
var arrLength = arr.length;
for(var i=0;i<arrLength;i++){for(j=0;j<arrLength-i-1;j++){if(arr[j]>arr[j+1]){var temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
console.log(arr);
微信公众号:天字一等