Better solution for "Repeat a String"

You do not really need the above or the closing bracket }. Instead of reassigning the result of the recursive call to str + str, just return all of it.

Before posting a working solution for comparison purpose, you should try to compare your solution to a solution on the Get a Hint page.

The third solution is basically the same as yours, but uses a ternary expression.

3 Likes