Repeat a string: Difference between revisions
Content added Content deleted
Line 559: | Line 559: | ||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |
||
<lang Mathematica>(* solution 1 *) |
<lang Mathematica>(* solution 1 *) |
||
Apply[StringJoin,ConstantArray[ |
rep[n_Integer,s_String]:=Apply[StringJoin,ConstantArray[s,{n}]] |
||
(* solution 2 *) |
(* solution 2 -- @@ is the infix form of Apply[] *) |
||
StringJoin @@ Table[ |
rep[n_Integer,s_String]:=StringJoin @@ Table[s, {n}] |
||
(* solution 3 -- demonstrating another of the large number of looping constructs available *) |
(* solution 3 -- demonstrating another of the large number of looping constructs available *) |
||
Nest[StringJoin[ |
rep[n_Integer,s_String]:=Nest[StringJoin[s, #] &, s, n-1] |
||
</lang> |
</lang> |
||