Last active
March 25, 2016 12:57
-
-
Save mwrouse/1f74c5687013c7dd73a8 to your computer and use it in GitHub Desktop.
I also wrote a JavaScript padding function, except in one line
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
/** | |
* 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; | |
} |
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
me too