Last active
August 22, 2018 12:48
-
-
Save oliverbth05/6f78568e06f367d32f27f9a1c73687fd to your computer and use it in GitHub Desktop.
Javascript Bubble Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bubbleSort(arr){ | |
let sortOccurred = true; | |
while (sortOccurred === true) { | |
for(var i = 0; i < arr.length; i++){ | |
if (arr[i] > arr[i + 1]) { | |
var a = arr[i]; | |
arr[i] = arr[i + 1]; | |
arr[i + 1] = a; | |
sortOccurred = true; | |
i = 0; | |
} | |
else { | |
sortOccurred = false | |
} | |
} | |
return arr | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment