大前端

前端学习之家-大前端

数组的操作之冒泡排序

<script>
    var arr = [7,76,3,9,2,34]
    for(var i=0;i<arr.length-1;i++){
        for(var j =0;j<arr.length-1-i;j++){
            if(arr[j]>arr[j+1]){
                [arr[j],arr[j+1]]=[arr[j+1],arr[j]]
            }
        }
    }
    console.log(arr)
</script>

 

发表评论:

Copyright Your WebSite.Some Rights Reserved.