Repeat a string: Difference between revisions

Line 476:
 
=={{header|JavaScript}}==
This solution creates an empty array of length n+1 null elements, then joinsuses themthe usingarray's thejoin targetmethod to effectively concatenate the string asn times. Note that extending the delimiterprototype of built-in objects is not a good idea if the code is to run in a shared workspace.
<lang javascript>String.prototype.repeat = function(n) {
return new Array(1 + n).join(this);
Line 482:
 
alert("ha".repeat(5)); // hahahahaha</lang>
 
 
=={{header|K}}==
Anonymous user