sandbox-js/bubblesort.js
2023-01-21 20:28:58 -05:00

14 lines
270 B
JavaScript

const array = [10, 8, 9, 7, 5, 5, 1, 3, 4, 2];
for (let i = 0; i < array.length; i++) {
for (let j = 1; j < array.length; j++) {
if (array[j] < array[j - 1]) {
const temp = array[j]
array[j] = array[j - 1]
array[j - 1] = temp;
}
}
}
console.log(array);