Global.String.Sorter (field, order)
factory to create functions for sorting objects in an array

  • Parameter String:
    name of the field each object is compared with
  • Parameter Number:
    order (ascending or descending)
  • Returns
    Function ready for use in Array.prototype.sort
Sourcecode in /home/hannes/helma/modules/core/String.js:
38:   String.Sorter = function(field, order) {
39:       if (!order)
40:           order = 1;
41:       var key = field + ":" + order;
42:       if (!String.Sorter.cache[key]) {
43:           String.Sorter.cache[key] = function(a, b) {
44:               var str1 = String(a[field] || String.NULL).toLowerCase();
45:               var str2 = String(b[field] || String.NULL).toLowerCase();
46:               if (str1 > str2)
47:                  return order * 1;
48:              if (str1 < str2)
49:                  return order * -1;
50:              return 0;
51:          };
52:      }
53:      return String.Sorter.cache[key];
54:  }