const bubbleSort = array => {
const { length } = array
let swapped = true
for (let i = 0; i < length - 1 && swapped; i++) {
swapped = false
for (let j = 0; j < length - 1 - i; j++) {
if (array[j] > array[j + 1]) {
const temp = array[j]
array[j] = array[j + 1]
array[j + 1] = temp
swapped = true
}
}
}
return array
}
console.log(bubbleSort([9, 1, 2, 2, 8, 3, 1, 10, 9, 0, 1, 2]))