MCPcopy Create free account
hub / github.com/betomoedano/JavaScript-Coding-Interview-Questions / bubbleSort

Function bubbleSort

sorting/bubble-sort.js:10–26  ·  view source on GitHub ↗
(array)

Source from the content-addressed store, hash-verified

8//
9
10function 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
28function swap(a, b, array) {
29 const temp = array[a];

Callers 1

bubble-sort.jsFile · 0.85

Calls 1

swapFunction · 0.70

Tested by

no test coverage detected