Repeat a string: Difference between revisions

Content added Content deleted
(added ocaml)
m (→‎{{header|JavaScript}}: more precise wording)
Line 24: Line 24:
}</lang>
}</lang>
=={{header|JavaScript}}==
=={{header|JavaScript}}==
This solution creates an empty array of size n+1 and then joins it 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 + parseInt(n, 10)).join(this);