Skip to content

Instantly share code, notes, and snippets.

@avitevet
Created September 24, 2013 09:22
Show Gist options
  • Save avitevet/6682382 to your computer and use it in GitHub Desktop.
Save avitevet/6682382 to your computer and use it in GitHub Desktop.
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