"At the contract shop where I work," writes John S., "I have been assigned to a new web-enabled mapping program to help take a look at some of the issues they've been having."

"When an item is added to a map, it is given a label, such as Item #1, Item #2, etc., with the number on the label incrementing for each new item. We had been having a problem where map labels were not being assigned uniquely when there were more than 100 items per map. It was always starting at Item #100 when reloading the map from the database. This was causing issues since it was the map label name that was being used for the unique identifier (don't get me started on that). Curious, I took a look at the code to decipher how the label ids were being assigned."

setCount: function(label) {
        var layer;
        var count;
        if (label.charAt(label.length - 2) == ' ' ) {
                layer = label.substring(0, label.length - 2);
                count = label.substring(label.length -1) * 1;
        } else {
                layer = label.substring(0, label.length - 3);
                count = label.substring(label.length - 2) * 1;
        if (this[layer] < count) {
                this[layer] = count ;

"Each time the map was loaded, a function iterated each layer to find the items assigned to that layer, and then to parse out the number from the code and keep track of the maximum id. Apparently they had the foresight to account for more than 10 items, but not for more than 100."

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!