Pad a given number with leading zeroes. Useful to make it a fixed width like with e.g. sprintf
in other programming langages.
- Example:
00001
,00012
,00123
,01234
,12345
pad(number, count);
// returns number with leading zeros
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter. And check my "JavaScript Golf Lessons" slides.
It might be good to highlight the limitations of this approach.
if a > 20 characters you run into scientific notation problems
([ 1e15 ] + 1234567891012345678901) = "10000000000000001.2345678910123457e+21"
if b is shorter than a your number will be truncated.