Created
March 13, 2014 21:32
-
-
Save bobbydeveaux/9537406 to your computer and use it in GitHub Desktop.
JS 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 main() { | |
for (var c = 0; c < 1000000; c++) { | |
bubble(); | |
} | |
} | |
function bubble() { | |
var array = [3,4,1,3,5,1,92,2,4124,424,52,12]; | |
for (var i = 0; i < array.length; i++) { | |
for (var y = 0; y < array.length - 1; y++) { | |
if (array[y+1] < array[y]) { | |
var t = array[y]; | |
array[y] = array[y + 1]; | |
array[y + 1] = t; | |
} | |
} | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NODE
$ time node bubble.js
real 0m0.484s
real 0m0.489s
real 0m0.491s
real 0m0.489s
real 0m0.496s