Skip to content

Instantly share code, notes, and snippets.

@mindplace
Created March 23, 2016 02:09
Show Gist options
  • Select an option

  • Save mindplace/520bf64ad30b20dd0f09 to your computer and use it in GitHub Desktop.

Select an option

Save mindplace/520bf64ad30b20dd0f09 to your computer and use it in GitHub Desktop.
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