Created
December 15, 2011 14:31
-
-
Save phiggins42/1481282 to your computer and use it in GitHub Desktop.
This file contains 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
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