Repeat a string: Difference between revisions

Line 727:
console.log("ha".repeat(5)); // hahahahaha</lang>
 
For larger numbers of repetitions, however, it proves significantly faster to progressively double a copy of the original string (concatenating it with itself),. and appending intermediateIntermediate stages of doubling are appended to an accumulator wherever required for binary composition of the target number.
 
See the technique of 'Egyptian Multiplication' described in the Rhind Mathematical Papyrus at the British Museum.
9,655

edits