Question: I need your help.

I'd like to create a function that would add some zeros in front of a number. The maximum numbers of digits that the total string should have is 6. Here are examples:

```
     9 -> 000009
    14 -> 000014
   230 -> 000230
  1459 -> 001459
 21055 -> 021055
987632 -> 987632 (Do nothing, there's already 6 digits)

```

Answer: 
One more . . . this one works with:

1. strings and numbers,
2. handles variable lengths, and
3. lets you chose the padding character

Code:

```
function padZerosToLength (value, minLength, padChar) {
    var iValLength= value.toString().length;
    return ((new Array((minLength + 1) - iValLength).join(padChar)) + value);
}

```

Here are some sample results with varying input:

```
padZerosToLength(1, 6, 0);       ===>  000001
padZerosToLength(12, 6, 0);      ===>  000012
padZerosToLength(123, 6, 0);     ===>  000123
padZerosToLength(1234, 6, 0);    ===>  001234
padZerosToLength(12345, 6, 0);   ===>  012345
padZerosToLength(123456, 6, 0);  ===>  123456

```

. . . with varying length:

```
padZerosToLength(1, 1, 0);  ===>  1
padZerosToLength(1, 2, 0);  ===>  01
padZerosToLength(1, 3, 0);  ===>  001
padZerosToLength(1, 4, 0);  ===>  0001
padZerosToLength(1, 5, 0);  ===>  00001
padZerosToLength(1, 6, 0);  ===>  000001

```

. . . and with varying padding character:

```
padZerosToLength(1, 6, 0);         ===>  000001
padZerosToLength(1, 6, 1);         ===>  111111
padZerosToLength(1, 6, "x");       ===>  xxxxx1
padZerosToLength(1, 6, ".");       ===>  .....1
padZerosToLength(1, 6, " ");       ===>       1
padZerosToLength(1, 6, "\u25CF");  ===>  ●●●●●1

```
A simple solution would be

```
    function addLeadingZeros (n, length)
    {
     var str = (n > 0 ? n : -n) + "";
     var zeros = "";
      for (var i = length - str.length; i > 0; i--)
         zeros += "0";
     zeros += str;
    return n >= 0 ? zeros : "-" + zeros;
    }

//addLeadingZeros (9, 3) =   "009"
//addLeadingZeros (15, 3) =  "015"
//addLeadingZeros (333, 3) = "333"

```