Almost Counting Past 100
by Mark Bowytz
in CodeSOD
on 2010-02-03
"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 ;
}
}