Give me Triangles [duplicate]

Given an integer n>0, write a program that will output an "isosceles" Triangle out of #'s of height n.

Examples:

n=3

  #
###
#####


n=1

#


n=5

    #
###
#####
#######
#########


This would be invalid:

#
###
#####
#######
#########

• Are leading and trailing newlines allowed? – S.S. Anne Feb 6 at 21:45
• How is this not a duplicate? XD – RGS Feb 6 at 22:06
• May we use another character besides #? – Shaggy Feb 7 at 0:38
• Which isosceles triangle permitted? For the input 3 is the triangle shown the only allowed triangle? Could you be a little more specific with you challenge? – Ad Hoc Garf Hunter Feb 7 at 2:47
• Related: Diamond creator + – Kevin Cruijssen Feb 7 at 9:06

Retina 0.8.2, 21 bytes

.+
$*# # ¶$.'$*$#$  Try it online! Link includes test cases. Output includes both leading and trailing newlines (but that helpfully separates the test cases!) Explanation: .+$*#


Convert the input to that many #s.

#
¶$.'$* $#$


For each #, output a new line, then as many spaces as there are #s remaining, then the #s so far, mirrored.

JavaScript V8, 48 bytes

f=(i,s=#
)=>i?(' '.repeat(--i)+s)+f(i,'##'+s):''


Test cases:

f=(i,s=#
)=>i?' '.repeat(--i)+s+f(i,'##'+s):''

console.log(f(1))
console.log(f(2))
console.log(f(3))
console.log(f(4))
console.log(f(5))
console.log(f(6))

JDK 13, 94 76 bytes

p->{for(int c=1;p>0;c+=2)System.out.println(" ".repeat(p--)+"#".repeat(c));}

TIO

With thanks to Kevin for some suggestions in the comments!

• Ah, hadn't seen you posted a second answer. This can be 76 bytes as mentioned in my comment on your Java 8 answer. – Kevin Cruijssen Feb 7 at 10:18

Keg, 22 bytes

:&1ɧ⑷:⑻$-⑬*$⑵;#*⑸(
'


Try it online!

A direct rip off of my answer here

Ruby, 42 bytes

Copying the Python answer from xnor.

f=->n,i=1{1/n;puts" "*~-n+?#*i;f[n-1,i+2]}


Try it online!