I am in need of a JavaScript function which can take a value and pad it to a given length (I need spaces, but anything would do). I found this:
Code:
Here's my take
I'm not so sure about it's performance, but I find it much more readable than other options I saw around here...
var replicate = function(len, char) {
return Array(len+1).join(char || ' ');
};
var padr = function(text, len, char) {
if (text.length >= len) return text;
return text + replicate(len-text.length, char);
};