Skip to content

Instantly share code, notes, and snippets.

@kwyn
Created April 6, 2014 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwyn/10003700 to your computer and use it in GitHub Desktop.
Save kwyn/10003700 to your computer and use it in GitHub Desktop.
var bubbleSort = function(array){
for(var i = 0; i < array.length-1 ; i++){
for(var j = 0; j < array.length-1 ; j++ ){
if(array[j]>array[j+1]){
var swap = array[j];
array[j] = array[j+1];
array[j+1] = swap;
}
}
}
};
var sorted = bubbleSort([5,4,3,2,1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment