(array)
| 8 | // |
| 9 | |
| 10 | function bubbleSort(array) { |
| 11 | let isSorted = false; |
| 12 | let iteration = 0; |
| 13 | |
| 14 | while (!isSorted) { |
| 15 | isSorted = true; |
| 16 | for (let i = 0; i < array.length - 1 - iteration; i++) { |
| 17 | if (array[i] > array[i + 1]) { |
| 18 | swap(i, i + 1, array); |
| 19 | isSorted = false; |
| 20 | } |
| 21 | } |
| 22 | iteration++; |
| 23 | } |
| 24 | |
| 25 | return array; |
| 26 | } |
| 27 | |
| 28 | function swap(a, b, array) { |
| 29 | const temp = array[a]; |