-
-
Save eengineergz/fd4acc0c89033bd219ebf9d3ec40b053 to your computer and use it in GitHub Desktop.
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
// Bubble Sort | |
function bubble(array) { | |
let sorted = true; | |
for (let i = 0; i < array.length; i++) { | |
let num1 = array[i]; | |
let num2 = array[i + 1]; | |
if (num1 > num2) { | |
array[i + 1] = num1; | |
array[i] = num2; | |
sorted = false; | |
} | |
} | |
if (sorted) { | |
return array; | |
} else { | |
return bubble(array); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment