sandbox-js/bubblesort.js

14 lines
270 B
JavaScript
Raw Normal View History

2023-01-22 02:28:58 +01:00
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);