Created
November 13, 2008 20:33
-
-
Save fogus/24606 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* merge sort in js */ | |
function sort(a) { | |
var mid = a.length>>1; | |
if (mid==0) return a; | |
var less = sort(a.slice(0,mid)); | |
var more = sort(a.slice(mid)); | |
var merged = []; | |
do { | |
if (more[0] < less[0]) { var t=less; less=more; more=t; } | |
merged.push(less.shift()); | |
} while (less.length > 0); | |
return merged.concat(more); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment