Created
March 23, 2016 02:09
-
-
Save mindplace/520bf64ad30b20dd0f09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(array) { | |
| var sorted = false; | |
| while (!sorted) { | |
| for (var i=0; i < array.length - 1; i++) { | |
| var a = array[i]; | |
| var b = array[i + 1]; | |
| if (a > b) { | |
| array[i] = b; | |
| array[i + 1] = a; | |
| break; | |
| } | |
| if (i === array.length - 2) { | |
| sorted = true; | |
| } | |
| } | |
| } | |
| console.log(array); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment