<!DOCTYPE html>
< html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript">
function max(arr){
var temp;
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr.length-i; j++) {
if(arr[j] > arr[j+1]){ //交换两数位置
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
return arr;
}
var arr = [4,7,76,3,76,87,45,3];
alert(max(arr));
</script>
</head>
<body>
</body>
< /html>
< html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript">
function max(arr){
var temp;
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr.length-i; j++) {
if(arr[j] > arr[j+1]){ //交换两数位置
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
return arr;
}
var arr = [4,7,76,3,76,87,45,3];
alert(max(arr));
</script>
</head>
<body>
</body>
< /html>