数组的升降序排列

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>排列</title>
</head>
<body>
    <script type="text/javascript">
        var arr = [1,10,30,2,3,5,100,500,200];
        function ascending(i,j) {
            return i-j;
        }

        function descending(i,j){
            return j-i;
        }

        alert(arr.sort(ascending));
        alert(arr.sort(descending));
    </script>
</body>
</html>

 

posted @ 2017-12-23 18:34  松歌  阅读(199)  评论(0编辑  收藏  举报