code: function compileMappings(oldMappings) {
      var mappings = oldMappings.slice(0);
  
      mappings.sort(function(map1, map2) {
        if (!map1.attribute) return 1;
        if (!map2.attribute) return -1;
  
        if (map1.attribute !== map2.attribute) {
          return map1.attribute < map2.attribute ? -1 : 1;
        }
        if (map1.value !== map2.value) {
          return map1.value < map2.value ? -1 : 1;
        }
        if (! ('replace' in map1) && ! ('replace' in map2)) {
          throw new Error('Conflicting mappings for attribute ' + map1.attribute + ' and value ' + map1.value);
        }
        if (map1.replace) {
          return 1;
        }
        return -1;
      });
  
      return mappings;
    }
docs: compileMappings  sort the mappings so that mappings for the same attribute and value go consecutive and inside those, those that change attributes appear first.