find the nth decagonal number in typescript

To find the nth decagonal number, you can use the following formula:

decagonal_number = n * (3n - 1) / 2 * 10

where n is the index of the decagonal number.

Here's the Typescript function that implements this formula:

index.ts
function getNthDecagonalNumber(n: number): number {
  return n * ((3 * n) - 1) / 2 * 10;
}
91 chars
4 lines

To use this function, simply call it with the index of the decagonal number you want to find:

index.ts
const nthDecagonalNumber = getNthDecagonalNumber(5); // returns 150
68 chars
2 lines

gistlibby LogSnag