find the nth decagonal number in javascript

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

dn = 3n^2 - 2n

Where n is the position of the decagonal number in the sequence.

Here's the javascript code:

index.tsx
function getDecagonalNumber(n) {
  return 3 * n * n - 2 * n;
}

// Example usage:
console.log(getDecagonalNumber(3)); // Output: 28
132 chars
7 lines

In this example, getDecagonalNumber(3) will return 28, which is the 3rd decagonal number in the sequence (1, 10, 28, 55, ...).

gistlibby LogSnag