Created
March 31, 2016 06:23
Star
You must be signed in to star a gist
leftpad.js
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
module.exports = leftpad; | |
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