Skip to content

Instantly share code, notes, and snippets.

@lgoldstien
Created December 13, 2013 13:28
Show Gist options
  • Save lgoldstien/7944210 to your computer and use it in GitHub Desktop.
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
/**
* 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