MCPcopy Create free account
hub / github.com/btholt/algorithms-exercises / bubbleSort

Function bubbleSort

specs/bubble-sort/bubble-sort.solution.test.js:13–28  ·  view source on GitHub ↗
(nums)

Source from the content-addressed store, hash-verified

11*/
12
13function bubbleSort(nums) {
14 let swapped = false;
15 do {
16 swapped = false;
17 for (let i = 0; i < nums.length; i++) {
18 // snapshot(nums);
19 if (nums[i] > nums[i + 1]) {
20 const temp = nums[i];
21 nums[i] = nums[i + 1];
22 nums[i + 1] = temp;
23 swapped = true;
24 }
25 }
26 } while (swapped);
27 // snapshot(nums);
28}
29
30// unit tests
31// do not modify the below code

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected