Skip to content

Instantly share code, notes, and snippets.

@ryaninvents
Created July 15, 2015 11:35
Show Gist options
  • Save ryaninvents/0f87a70f60a477b19443 to your computer and use it in GitHub Desktop.
Save ryaninvents/0f87a70f60a477b19443 to your computer and use it in GitHub Desktop.
Pad function

I write a pad function fairly often, and I've never been so satisfied with an implementation as I am with this one.

function pad(n,d){
d = d || 2;
return (Array.apply(null, {length: d}).map(function () {
return '0';
}).join('') + String(n)).substr(-d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment