Hey,
i’ve implemented the bubble sort but when running the test i get the following error:
bubbleSort should not use the built-in .sort()
Here’s the code
function bubbleSort(array) {
var sorted = false;
while(!sorted) {
let swap=0;
for( let i=0; i<array.length-1; i++) {
if(array[i] > array[i+1]) {
let aux = array[i+1];
array[i+1] = array[i];
array[i] = aux;
swap++;
}
}
sorted = swap === 0;
}
return array;
}
bubbleSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
** browser information:**
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
.
Challenge: Implement Bubble Sort
Link to the challenge: