code: function (productTypes, department) {
  
              function sizeMapToArray(sizeMap, departmentName) {
                  var ret = [];
                  for (var sizeName in sizeMap) {
                      if (sizeMap.hasOwnProperty(sizeName)) {
                          ret.push({
                              name: sizeName,
                              sizeWeight: sizeMap[sizeName].sizeWeight,
                              departmentName: departmentName,
                              productTypes: sizeMap[sizeName].productTypes
                          });
                      }
                  }
  
                  ret.sort(function(a, b) {
                      return (a.sizeWeight || 0) - (b.sizeWeight || 0)
                  });
  
                  return ret;
              }
  
              var departmentSizeMap = productTypeDepartmentToSizeMap;
  
              if (productTypes) {
                  var departmentHash,
                      key, departments;
  
                  departmentSizeMap = {};
                  productTypes.each(function (productType) {
                      if (department) {
                          departments = [department];
                      } else {
                          departments = productTypeToDepartmentsMap[productType.$.id];
                      }
                      if (departments) {
                          for (var i = 0; i < departments.length; i++) {
                              key = departments[i].$.name;
                              departmentHash = departmentSizeMap[key] = departmentSizeMap[key] || {};
                              if (productType.$.sizes) {
                                  productType.$.sizes.each(function (size) {
                                      if (!departmentHash[size.$.name]) {
                                          departmentHash[size.$.name] = {
                                              productTypes: [],
                                              sizeWeight: size.$.weight
                                          };
                                      }
                                      departmentHash[size.$.name].productTypes.push(productType);
                                  });
                              }
                          }
                      }
                  });
              }
              var groups = [],
                  group;
              for (var departmentName in departmentSizeMap) {
                  if (departmentSizeMap.hasOwnProperty(departmentName)) {
                      group = {
                          name: departmentName,
                          items: sizeMapToArray(departmentSizeMap[departmentName], departmentName)
                      };
                      groups.push(group);
                  }
              }
  
              return groups;
  
          }
docs: *
  
  @returns {Array}