Jump to content

Repeat a string: Difference between revisions

Line 559:
=={{header|Mathematica}}==
<lang Mathematica>(* solution 1 *)
rep[n_Integer,s_String]:=Apply[StringJoin,ConstantArray["HA"s,{100n}]]
 
(* solution 2 -- @@ is the infix form of Apply[] *)
rep[n_Integer,s_String]:=StringJoin @@ Table["HA"s, {100n}]
 
(* solution 3 -- demonstrating another of the large number of looping constructs available *)
rep[n_Integer,s_String]:=Nest[StringJoin["HA"s, #] &, "HA"s, 99n-1]
</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.