Usually, the sorting methods expect that the comparison method returns simply a 0 when two items are equal, any negative value when the first is less than the second and a positive value when the first is greater then the second. The method will
not build up a collection of comparison results; it will instead evaluate each result to determine whether to
swap the two compared items and will repeat until all necessary comparisons have been performed.
I'm not expert enough with javascript to post some code, but the following could help:
You are treating each item not as a single value/object, but as a pair of objects, where the first object is the item's type and the second is the item itself.
For each pair of items (a and b) you should compare the types of the two items and then, if they are equal, compare the items themself.
Some pseudo-code of
mySortRule could be
if (value1 == value2)
return 0;
var priority1 = getPriorityOf(value1);
var priority2 = getPriorityOf(value2);
var result = priority1.CompareTo(priority2);
if (result != 0)
return result;
result = value1.CompareTo(value2);
if (result != 0)
return result;
return 0;
together with a possible
getPriorityOf like
if (value is numeric)
return 1;
if (value is string)
return 2;
return Number.MAX_VALUE;