标签:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>sort排序</title>
</head>
<body>
<script type="text/javascript">
var arr = [3,1,0,7,6,5,4,9];
document.write("原数组:"+arr+"<br />");
//升序参数
function ascArr(x,y){
if(x>y){
return 1;
}else{
return -1;
}
}
//降序参数
function descArr(x,y){
if(x>y){
return -1;
}else{
return 1;
}
}
document.write("升序后的数组:"+arr.sort(ascArr)+"<br />");
document.write("降序后的数组:"+arr.sort(descArr));
</script>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/yifeizeng168/p/5014256.html