TypeScript's Type System, 71 bytes
type F<A extends{}[]=[]>=A extends{length:10}?A:F<[...A,"**********"]>;
Try it at the TypeScript playground!
Just barely longer than Java :)
Type F recursively appends "**********"
to array A
until A
's length is 10.
If you need the output to be a string and not a list of lines, here's an 83 byte version:
//@ts-ignore
type F<A=[],S="">=A extends{length:10}?S:F<[...A,1],`${S}
**********`>
Try it at the TypeScript playground!
This one recursively appends "\n**********"
to string S
while appending 1
to array A
until A
's length is 10. We need to do it like this because you can't get the length of a string in TypeScript's type system without converting it to a list first, so it's shorter to have a list just to keep track of iteration.
The //@ts-ignore
is necessary because the compiler doesn't want to spread A
, which it can't tell is a list, or inject S
, which it can't tell is a string, into the main string. We could explicitly tell the compiler that A extends{}[]
(A is a list of something) and that S extends string
, but that comes out to be a lot longer than just ignoring the errors.