Skip to content

Instantly share code, notes, and snippets.

@Vovans
Created March 28, 2016 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vovans/13b179d5b38b63877a85 to your computer and use it in GitHub Desktop.
Save Vovans/13b179d5b38b63877a85 to your computer and use it in GitHub Desktop.
left-pad
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;
}
@Saluev
Copy link

Saluev commented Mar 28, 2016

BTW, why not return Array(len).join(ch) + str?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment