Created
November 2, 2014 14:16
-
-
Save shigemk2/e571a43f107e1f7f5cb5 to your computer and use it in GitHub Desktop.
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 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