javascript表格排序原理

  1. 代码:
    var arr = new Array(
        3,2,6,1,5
    )
    var flag = true
    function mySort(arr){
    if(flag){
        arr = arr.sort(function(a,b){
            return a-b
        })
    }else{
        arr = arr.sort(function(a,b){
            return b-a
        })
    }
    flag = !flag
    return arr
    }
    mySort(arr)
    console.log(arr)
    mySort(arr)
    console.log(arr)
    mySort(arr)
    console.log(arr)
  2. 输出:
    [ 1, 2, 3, 5, 6 ]
    [ 6, 5, 3, 2, 1 ]
    [ 1, 2, 3, 5, 6 ]

当前标题:javascript表格排序原理
转载源于:http://scyanting.com/article/pjseoh.html