Nest a string inside an array n times

Java and C#, 62 bytes

Object f(String s,int n){return n<1?s:new Object[]{f(s,n-1)};}

Should work without modification in both Java and C#.


05AB1E, 3 bytes

Code

`F)

Explanation

`   # Flatten the input array on the stack.
 F  # Element_2 times do:
  ) # Wrap the total stack into a single array.

This means that this also works for the 0-testcase, since the string is already on the stack.

Try it online!


Jelly, 2 bytes

Slightly confusing, since: (1) Jelly has no strings, only lists of characters; and (2); the output wont show the nesting. To see that this actually is doing what is asked look at a Python string representation of the result with:

W¡ŒṘ

An extra pair of [] will be present since the string itself will be a list of characters. For example

How?

W¡ - Main link: s, n
W  - wrap left, initially s, in a list
 ¡ - repeat previous link n times

The proof-of-concept code adds:

W¡ŒṘ - Main link: s, n
  ŒṘ - Python string representation