Skip to content
Snippets Groups Projects
Commit 6bf3acfb authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Generalize lpad() to lpadn() for any length

parent 5ec0e9c3
No related branches found
No related tags found
No related merge requests found
...@@ -17,14 +17,24 @@ hr = "========================================"; // horizontal rule ...@@ -17,14 +17,24 @@ hr = "========================================"; // horizontal rule
hr = hr + hr; hr = hr + hr;
function lpad(str) { function lpadn(str, len) {
if (lengthOf("" + str) < 2) { /* left-pad a string with zeros to a given total length n */
cur_len = lengthOf("" + str);
if (cur_len < len) {
for (i=0; i<(len-cur_len); i++) {
str = "0" + str; str = "0" + str;
} }
}
return str; return str;
} }
function lpad(str) {
/* shortcut for padding to length of two */
return lpadn(str, 2);
}
function get_tileconfig_files(dir) { function get_tileconfig_files(dir) {
/* Generate an array with tile config files. /* Generate an array with tile config files.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment