I write a pad function fairly often, and I've never been so satisfied with an implementation as I am with this one.
Created
July 15, 2015 11:35
-
-
Save ryaninvents/0f87a70f60a477b19443 to your computer and use it in GitHub Desktop.
Pad function
This file contains hidden or 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
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