To find the nth pentagonal number, we can use the formula:
Pn = n(3n - 1) / 2
Where Pn is the nth pentagonal number.
We can implement this in Typescript as follows:
index.ts236 chars9 lines
In the example usage, we pass in the value 6
for the nth
parameter, which will output:
index.ts32 chars2 lines
This means that the 6th pentagonal number is 35.
gistlibby LogSnag