svc.copies = svc.copies.sort(
function (a, b) {
function compare_array (x, y, i) {
- if (x[i] && y[i]) { // both have values
- if (x[i] == y[i]) { // need to look deeper
- return compare_array(x, y, ++i);
- }
-
- if (x[i] < y[i]) { // x is first
- return -1;
- } else if (x[i] > y[i]) { // y is first
- return 1;
- }
-
- } else { // no orgs to compare ...
- if (x[i]) return -1;
- if (y[i]) return 1;
- }
- return 0;
+ // the longer array "wins" if we run off the end of either:
+ if(i >= x.length || i >= y.length){ return y.length - x.length; }
+ // return a value if we find a difference, otherwise recurse:
+ return x[i].localeCompare(y[i]) || compare_array(x,y,i+1);
}
var owner_order = compare_array(a.owner_list, b.owner_list, 0);