This code passes but i want to be sure if this is actually bubble sort.
I tried the same code in selection sort and it passed. I think labs only check if the array is sorted not what sorting algorithm we are using.
Your code so far
function bubbleSort(array) {
for (let i = 0; i < array.length; i++) {
if (array[i + 1] < array[i]) {
let temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
}
}
for (let i = 0; i < array.length; i++) {
if (array[i + 1] < array[i]) {
bubbleSort(array);
break;
}
}
return array
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Challenge Information:
Implement the Bubble Sort Algorithm - Implement the Bubble Sort Algorithm