Last active
October 11, 2016 12:37
-
-
Save vidul-nikolaev-petrov/18060bb18e6fdf83ef5e to your computer and use it in GitHub Desktop.
Somewhat more concise 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(array) { | |
var swapped; | |
for (var i = 0; i < array.length - 1; i++) { | |
if (array[i] > array[i + 1]) { | |
var tmp = array[i + 1]; | |
array[i + 1] = array[i]; | |
array[i] = tmp; | |
swapped = true; | |
} | |
} | |
swapped && bubbleSort(array); | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment