MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / alternativeBubbleSort

Function alternativeBubbleSort

Sorts/BubbleSort.js:46–60  ·  view source on GitHub ↗
(arr)

Source from the content-addressed store, hash-verified

44 * Using a while loop and a for loop.
45 */
46export function alternativeBubbleSort(arr) {
47 let swapped = true
48
49 while (swapped) {
50 swapped = false
51 for (let i = 0; i < arr.length - 1; i++) {
52 if (arr[i] > arr[i + 1]) {
53 ;[arr[i], arr[i + 1]] = [arr[i + 1], arr[i]]
54 swapped = true
55 }
56 }
57 }
58
59 return arr
60}

Callers 1

BubbleSort.test.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected