Skip to content

Instantly share code, notes, and snippets.

@phiggins42
Created December 15, 2011 14:31
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 phiggins42/1481282 to your computer and use it in GitHub Desktop.
Save phiggins42/1481282 to your computer and use it in GitHub Desktop.
String.prototype.repr = function(n){
return Array(n + 1).join(this);
}
String.prototype.lpad = function(/* Int */ length, /* String */ pad){
// summary: left pad this string to become `length` using an optional `pad` character
return (pad || " ").repr(length - this.length) + this;
}
String.prototype.rpad = function(length, pad){
return this + (pad || " ").repr(length - this.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment