Recursion to Repeat a String n Number of Times

Published by Nomove in

Create a recursive function that takes two parameters and repeats the string n number of times. The first parameter txt is the string to be repeated and the second parameter is the number of times the string is to be repeated.

Examples

Repetition("ab", 3) ➞ "ababab"

Repetition("kiwi", 1) ➞ "kiwi"

Repetition("cherry", 2) ➞ "cherrycherry"

Notes

The second parameter of the function is positive integer.

Watch a quick demo on how Edabit works.