Skip to content

Instantly share code, notes, and snippets.

@avitevet
Created Sep 24, 2013
Embed
What would you like to do?
general string left padding function in coffeescript
# 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