TylerRosen
4/29/2017 - 6:31 PM

Bubble Sort.js

var bubbleSort = function(arr){

    var count = 0
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] > arr[i+1]){
            var t = arr[i]
            arr[i] = arr[i+1]
            arr[i+1] = t
            count ++
        }
    }
    if (count >0){
        bubbleSort(arr)
    }

    return arr

}


console.log(bubbleSort([3,5,8,2,3,4,8,9]))