function bubbleSort(arr){
let len = arr.length
for(let i = len - 1, temp; i > 0; i--){
for(let j = 0; j < i; j++){
temp = arr[i]
if(temp < arr[j]){
arr[i] = arr[j]
arr[j] = temp
}
}
}
return arr
}
bubbleSort([23, 4, -12, 8, 45, 0, -5])
function ArrayList(){
let arr = []
let swap = function(arr, index1, index2){
[arr[index1], arr[index2]] = [arr[index2], arr[index1]]
}
this.insertItem = function(item){
arr.push(item)
}
this.toString = function(){
return arr.join()
}
this.bubbleSort = function(){
let len = arr.length
for(let i = 0; i < len; i++){
for(let j = 0; j < len - 1 - i; j++){
if(arr[j] > arr[j+1]){
swap(arr, j, j+1)
}
}
}
}
}
function test(size){
let arr_list = new ArrayList()
for(let i = size; i > 0; i--){
arr_list.insertItem(i)
}
return arr_list
}
let newTest = test(5)
console.log(newTest.toString())
newTest.bubbleSort()
console.log(newTest.toString())
console