Skip to content

Instantly share code, notes, and snippets.

@kaochenlong
Created November 16, 2011 15:12
Show Gist options
  • Save kaochenlong/1370294 to your computer and use it in GitHub Desktop.
Save kaochenlong/1370294 to your computer and use it in GitHub Desktop.
padding_left = (str, len) ->
str = "#{str}"
str = "0#{str}" while str.length < len
str
padding_right = (str, len) ->
str = "#{str}"
str = "#{str}0" while str.length < len
str
console.log(padding_left 123, 5) # 00123
console.log(padding_right 123, 5) # 12300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment