Print the Pattern

You are asked to write a function named star_pattern that recursively prints a pattern of stars (*) up to a given depth n. The pattern starts with n stars, then it prints n-1 stars in the next line, and it continues this way until it reaches a line with 1 star. Then the pattern starts to ascend back to n stars incrementally in the same way.
Your function needs to be recursive, meaning it should call itself in order to solve the problem.
Input
Output
star_pattern(3)
*** ** * ** ***
star_pattern(5)
***** **** *** ** * ** *** **** *****
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue