Sort Array


/*
 * Comparator for the Array.sort method
 * Sets the sort order for characters
 * Ignores case
 * Sorts German umlauts (ä == a, ß == s, ...)
 * 
 * @param a first argument
 * @param b second argument
 * @return  
 * 		 0, if a = b
 *  	-1, if a > b
 *  	 1, else
 */
function strComp(a, b)	{
	a = a.toLowerCase();
	a = a.replace(/ä/g,"a");
	a = a.replace(/ö/g,"o");
	a = a.replace(/ü/g,"u");
	a = a.replace(/ß/g,"s");

	b = b.toLowerCase();
	b = b.replace(/ä/g,"a");
	b = b.replace(/ö/g,"o");
	b = b.replace(/ü/g,"u");
	b = b.replace(/ß/g,"s");

	return(a==b)?0:(a>b)?1:-1;
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...