Repeat a string: Difference between revisions

Line 723:
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 theintermediate resultstages of doubling 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