Skip to content

Instantly share code, notes, and snippets.

@gcpantazis
Created June 4, 2012 03:35
Show Gist options
  • Save gcpantazis/2866174 to your computer and use it in GitHub Desktop.
Save gcpantazis/2866174 to your computer and use it in GitHub Desktop.
Sort strings and numbers.
var x = [1,3,'b',5,2,4,'a'];
x.sort(function(a,b){
if ( typeof a === typeof b ) {
return (a > b);
} else {
return typeof a > typeof b;
}
});
// [1, 2, 3, 4, 5, "a", "b"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment