I need a function in JavaScript (for use in Node) that increments numbers in a string as follows:
"0", "1", "2", "3", ..., "8", "9", "00", "01", "02"
and so on. How would I go about doing this? I can think of a long way with lots of conditionals, but that probably won't run optimally.
What I have so far:
var count = "0";
function increment() {
var number = parseInt(count), digits = count.length;
var upDigit = true;
for (var i = 0; i < digits; i++) {
if (i !== 9)
upDigit = false;
}
if (upDigit) {
var zeros = "";
for (var i = 0; i <= digits; i++) {
zeros += "0";
}
count = zeros;
} else {
count = number++;
}
}