Created
June 4, 2012 03:35
-
-
Save gcpantazis/2866174 to your computer and use it in GitHub Desktop.
Sort strings and numbers.
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
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