I’m working on learning data structures and different algorithms. One of the first ones is Bubble Sort: const bubbleSort = array => { let noSwaps; for (let i = array.length; i > 0; i–) { noSwaps = true; for (let j = 0; j < i - 1; j++) { if (array[j] > array[j + 1]) { [array[j], array[j + 1]] = [array[j + 1], array[j]]; noSwaps = false; } } if (noSwaps) break; } return array; }; Bubble Sort takes O(n^2) time in the worst case because you have two nested loops.