Repeat a string: Difference between revisions

Content added Content deleted
(→‎{{header|JavaScript}}: using n in an arithmetic operation converts it to a number automatically)
Line 356: Line 356:
This solution creates an array of n+1 null elements, then joins them using the target string as the delimiter
This solution creates an array of n+1 null elements, then joins them using the target string as the delimiter
<lang javascript>String.prototype.repeat = function(n) {
<lang javascript>String.prototype.repeat = function(n) {
return new Array(1 + parseInt(n, 10)).join(this);
return new Array(1 + n).join(this);
}
}