zoukankan      html  css  js  c++  java
  • 将数组升序或降序

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>将数组升序或降序</title>
    <script type="text/javascript">
    var Descending = function(arr) {

    var i, j, temp, len = arr.length;

    for (i = 0; i < len; i++) {

    for (j = i + 1; j < len; j++) {

    if (arr[i] < arr[j]) {
    temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
    }
    }
    }

    return arr;
    }

    var arr = [1,2,3,4,5,6,7,8,9];
    Descending(arr);
    alert(arr);
    </script>
    </head>

    <body>
    </body>

    </html>

  • 相关阅读:
    毕业论文格式
    2018.12.14
    关于百度搜索引擎的优缺点
    2018.12.13
    2018.12.12
    2018.12.11
    2108.12.10
    2018.12.9
    2018.12.8
    2018.12.7
  • 原文地址:https://www.cnblogs.com/clear93/p/4627017.html
Copyright © 2011-2022 走看看