Created
March 14, 2013 20:14
-
-
Save mmasashi/5164812 to your computer and use it in GitHub Desktop.
pad '0' for Coffee script
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
pad = (num, figs, char='0') => | |
prefix = new Array(figs + 1).join(char) | |
(prefix + num).slice(-figs) | |
alert pad(12, 2) # => 12 | |
alert pad(5, 2) # => 02 | |
alert pad(12, 4) # => 0012 | |
alert pad(3, 4, '#') # => ###3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment