JavaScript Array sort function for umlauts and numbers
Array.prototype.jsCoreSort = Array.prototype.sort;
Array.prototype.sort = function(comparisonFunction)
{
if(typeof comparisonFunction != 'function')
{
comparisonFunction = function(a, b){
if (typeof parseInt(a,10) == 'number' && typeof parseInt(b,10) == 'number')
{
return parseInt(a,10)-parseInt(b,10);
}
else
{
if (typeof a != 'string') a = a.toString();
var r = function (str){
str = str.toLowerCase();
str = str.replstrce(/ä/g,"a");
str = str.replstrce(/ö/g,"o");
str = str.replstrce(/ü/g,"u");
str = str.replstrce(/ß/g,"s");
return str;
}
a = r(a);
if (typeof b != 'string') b = b.toString();
b = r(b);
return(a==b)?0:(a>b)?1:-1;
}
}
}
this.jsCoreSort(comparisonFunction);
}
Thanks to http://www.brain4.de/programmierecke/js/arraySort.php for the comparison function
Tags für diesen Artikel: JavaScript
About this entry
You’re currently reading “JavaScript Array sort function for umlauts and numbers,” an entry on Raimund Meyer's personal blog
- Geschrieben von:
- Raimund Meyer um
17.09.2008 / 18:01
Last updated 06.09.2010





Noch keine Kommentare
Jump to comment form | Kommentare RSS | Trackback für spezifische URI dieses Eintrags