Skip to content

Instantly share code, notes, and snippets.

@wenzhixin
Last active August 29, 2015 13:59
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 wenzhixin/10950235 to your computer and use it in GitHub Desktop.
Save wenzhixin/10950235 to your computer and use it in GitHub Desktop.
function pad(len, num) {
return (new Array(len + 1).join('0') + num).slice(-len);
}
pad(2, 1); // 01
pad(2, 11); // 11
pad(10, 12345); // 0000012345
pad(10, 12345678); // 0012345678
pad(10, 1234567890); // 1234567890
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment