Last active
June 20, 2017 10:26
-
-
Save warlock/ae79b0dc8344bb36f1098e916e2efc7c to your computer and use it in GitHub Desktop.
Javascript Pad : How To Add/Insert Leading Zeros To Numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pad = (n, width, z) => { | |
z = z || '0' | |
n = n + '' | |
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment