Yeah, I was right, here is a bit simpler method (requires IE 5.5 or better - or just about any other browser):
Code:
<script type="text/javascript">
Array.prototype.numlet = function(){
var t = [], r = [], o = {}, i, p,
c = function(item){return isNaN(parseInt(item.toString(10)))? 9999999 : parseInt(item);};
for (i = this.length - 1; i > -1; --i)
if(o[c(this[i])]) o[c(this[i])].push(this[i]);
else o[c(this[i])] = [this[i]];
for (p in o) t.push(p), o[p].sort();
t.sort(function(a, b){return b - a;});
for (i = t.length - 1; i > -1; --i)
r = r.concat(o[t[i]]);
for (i = this.length - 1; i > -1; --i)
this[i] = r[i];
};
var x = ['2c','b','4z','3y','w','3c','4t','2a','9a', '3q'];
x.numlet();
alert(x);
</script>
It avoids the issue with numbers vs strings by making everything a string, and will work with arrays having entries like:
974gthw
and:
black
as well as with the typical sort of entries you mentioned.
To get the letter entries to come first in this version, just change the highlighted 9999999 to 0.
Bookmarks