Created
September 24, 2013 09:22
-
-
Save avitevet/6682382 to your computer and use it in GitHub Desktop.
general string left padding function in coffeescript
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
# val = the value to pad | |
# length = the length of the padded string | |
# padChar = the character to use for padding. Defaults to '0' | |
pad = (val, length, padChar = '0') -> | |
val += '' | |
numPads = length - val.length | |
if (numPads > 0) then new Array(numPads + 1).join(padChar) + val else val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment