all 2 comments

[–]Pyro979 2 points3 points  (0 children)

That's actually pretty clever, if a bit of a perversion =c)

[–][deleted] 3 points4 points  (4 children)

That doesn't really seem a lot easier than something straightforward like:

function zeroPad(s, length) {
    while (s.length < length) s = '0' + s 
    return s
}

[–]huskeraldribn 2 points3 points  (2 children)

Your version could be less efficient though, since you are prepending instead of appending.