1
2function bubbleSort(arr){
3 var len = arr.length;
4 for (var i = len-1; i>=0; i--){
5 for(var j = 1; j<=i; j++){
6 if(arr[j-1]>arr[j]){
7 var temp = arr[j-1];
8 arr[j-1] = arr[j];
9 arr[j] = temp;
10 }
11 }
12 }
13 return arr;
14}
15bubbleSort([7,5,2,4,3,9]); //[2, 3, 4, 5, 7, 9]
16bubbleSort([9,7,5,4,3,1]); //[1, 3, 4, 5, 7, 9]
17bubbleSort([1,2,3,4,5,6]); //[1, 2, 3, 4, 5, 6]
18