Created
March 17, 2010 15:36
-
-
Save furf/335366 to your computer and use it in GitHub Desktop.
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 addLeadingZeros(c,l,a){return(a=[]).join(a[l-(''+c).length-1]=0)+c;} | |
// also... | |
function addLeadingZeros(v,l,i,n){for(i=(v+='').length,n=l||2;i<n;++i){v=0+v;}return v;} |
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 repeat(c,n,a){return(a=[]).join(a[n-1]=c);} | |
// usage | |
repeat('x', 3); // returns "xxx" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment