Javascript String fill(str, toLen)
String.prototype.fill = function(str, toLen) { if (this.length >= toLen) { return this;//from w w w .j a va 2 s . co m } else { str = str || " "; var fillLen = toLen - this.length; var reps = fillLen / str.length; var remainder = fillLen % str.length; return str.repeat(reps) + str.substring(0, remainder) + this; } }