Skip to content

Instantly share code, notes, and snippets.

@laziel
Created March 31, 2016 06:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save laziel/d9fa27abd1b327d68bbfe075dce2037d to your computer and use it in GitHub Desktop.
leftpad.js
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