I have this Bubble Sort algorithm here
let bubbleSort = (array) => {
for (let j=0;j<array.length;j++) {
for (let i=0;i<array.length;i++) {
if(array[i] > array[i+1]) {
let temp = array[i];
array[i] = array[i+1];
array[i+1] = temp;
}
}
}
return array;
}
I understand how it works, but I don't understand what the if statement means:
let temp = array[i];
array[i] = array[i+1];
array[i+1] = temp;
Edit: I can't mark all answers as solved, but they helped me. Thank you!