bubble sort html code example
Example: bubble sort javascript
function bubblesort(array) {
len = array.length;
for (let i = 0; i < len; i++) {
for (let j = 0; j < len - i; j++) {
let a = array[j];
if (a != array[-1]) {
var b = array[j + 1];
if (a > b) {
array[j] = b;
array[j + 1] = a;
}
}
}
}
}
let array = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
bubblesort(array);
console.log(array)