BubbleSort
1234567891011121314151617
const input = [99, 44, 6, 2, 1, 5, 63, 87, 283, 4, 0];
const bubbuleSort = (a) => {
for (let i = 0; i <= a.length; i++) {
for (let j = 0; j < a.length; j++) {
if (a[j] > a[j + 1]) {
let temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
return a;
};
console.log(bubbuleSort(input));
JavaScript
INFO