Created
March 24, 2016 06:12
-
-
Save leohxj/ce6566a720a9b409da2e to your computer and use it in GitHub Desktop.
leftpad: 左侧位数不足补字符
This file contains hidden or 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
| function leftpad (str, len, ch) { | |
| str = String(str); | |
| var i = -1; | |
| if (!ch && ch !== 0) ch = ' '; | |
| len = len - str.length; | |
| while (++i < len) { | |
| str = ch + str; | |
| } | |
| return str; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment