Skip to content

Instantly share code, notes, and snippets.

@mwrouse
Last active March 25, 2016 12:57
Show Gist options
  • Save mwrouse/1f74c5687013c7dd73a8 to your computer and use it in GitHub Desktop.
Save mwrouse/1f74c5687013c7dd73a8 to your computer and use it in GitHub Desktop.
I also wrote a JavaScript padding function, except in one line
/**
* Right Pad
*
* str - the string to pad
* chr - the character to use as padding
* n - the desired string length
*/
function rpad(str, chr, n)
{
return ((str+='').length < n && chr) ? rpad(str + chr, chr, n) : str;
}
@mwrouse
Copy link
Author

mwrouse commented Mar 25, 2016

Okay, I guess you win with your newer syntax... Fair enough.

Although, that only works when input, and pad are strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment