码迷,mamicode.com
首页 > 编程语言 > 详细

数组的高级API-sort

时间:2018-06-24 15:11:21      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:div   数组   pat   存在   pre   ima   doctype   har   TE   

按升降序排列数组项。
本身存在的问题:只能通过第一位排列。
解决方法:通过回调函数进行规制设置。

a - b 升序。

b - a 降续。

其内部运用了冒泡排序

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=script, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        var arr = [100,10,8,-10,1000];

       console.log( arr.sort(function (a,b){
            return a - b;
        }));

        console.log( arr.sort(function (a,b){
            return b - a;
        }));


    </script>
</body>
</html>

技术分享图片

 

数组的高级API-sort

标签:div   数组   pat   存在   pre   ima   doctype   har   TE   

原文地址:https://www.cnblogs.com/-Tony/p/9220370.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!