Skip to content

Instantly share code, notes, and snippets.

@furf
Created March 17, 2010 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save furf/335366 to your computer and use it in GitHub Desktop.
Save furf/335366 to your computer and use it in GitHub Desktop.
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;}
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