Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created November 2, 2014 14:16
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 shigemk2/e571a43f107e1f7f5cb5 to your computer and use it in GitHub Desktop.
Save shigemk2/e571a43f107e1f7f5cb5 to your computer and use it in GitHub Desktop.
function bubble(x) {
for(var i=0; i<x.length-1; i++) {
for(var j=x.length-1; j>i; j--) {
if(x[j] < x[j-1]) {
var bswap = x[j];
x[j] = x[j-1];
x[j-1] = bswap;
};
};
};
return x;
};
console.log(bubble([4, 6, 9, 8, 3, 5, 1, 7, 2]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment