Created
December 13, 2013 13:28
-
-
Save lgoldstien/7944210 to your computer and use it in GitHub Desktop.
Pad out "y" string with "x" character until it is "z" characters long
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
/** | |
* Pad a string to a particular length | |
* @param {string} string - The string to be padded | |
* @param {string} paddingChar - The character used to pad out the string | |
* @param {int} count - The desired total length of the string | |
* @return {string} - The padded string | |
*/ | |
var stringPad = function (string, paddingChar, paddedLength) { | |
var outputString = String(string); | |
while (outputString.length < paddedLength) { | |
outputString = String(paddingChar) + outputString; | |
} | |
return outputString; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment