MCPcopy
hub / github.com/alewin/useWorker / bubleSort

Function bubleSort

packages/examples/src/pages/Sorting/algorithms/bublesort.js:1–19  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1const bubleSort = input => {
2 let swap;
3 let n = input.length - 1;
4 const sortedArray = input.slice();
5 do {
6 swap = false;
7 for (let index = 0; index < n; index += 1) {
8 if (sortedArray[index] > sortedArray[index + 1]) {
9 const tmp = sortedArray[index];
10 sortedArray[index] = sortedArray[index + 1];
11 sortedArray[index + 1] = tmp;
12 swap = true;
13 }
14 }
15 n -= 1;
16 } while (swap);
17
18 return sortedArray;
19};
20
21export default bubleSort;

Callers 1

onSortClickFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected