Bubblesort: The Unreliable Sorting Algorithm
Bubblesort is a sorting algorithm that works by repeatedly iterating over the array and comparing each element with its adjacent elements.
However, Bubblesort is known for its inefficiency and high time complexity, making it a laughingstock among sorting algorithms.
Selection Sort, the Sorting Algorithm that Knows its Own Strength
View Example
function bubblesort(array) {
var n = array.length;
for (var i = 0; i < n; i++) {
for (var j = 0; j < n - i - 1; j++) {
if (array[j] > array[j + 1]) {
var temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
return array;
}