Is there a smart way to convert numbers to string and automatically add zeroes so the length is the same as the maximum?
like this:
for (var i=0; i<30; i++) {
var c = i.toString();
if (c.length == 1) {
c = '0'+=c;
}
}
But smarter
There’s a million ways, this is one of them, and its actually quite efficient too..
UPDATE 2
Here’s code for the ‘third interpretation of the OP’s question
This will output [“00”, “01”, “02” …. ,”30″]
UPDATE 1 adapted the code for both ‘possible’ interpretations of the OP’s question.
If what you want is code that based on n=5 , max = 30 produces 29 “0”s followed by “5” then this is the code you want
If what you want is code that based on n=5 , max = 30 produces 2 (the length of 30.toString()) “0”s followed by “5” then this is the code you want
The only difference here is in the first line.
These do not use string concatenation (extremely inefficient), instead they use
Array.unshiftandArray.join