Function triangularNumber

  • Category

    Calculate the nth triangular number for a provided number.

    Time complexity: O(1)

    Space complexity: O(1)

    Parameters

    • value: number

      The number to calculate the triangular number for

    Returns number

    The nth triangular number for the provided value

    Math

    triangularNumber(2); // 3
    
  • Category

    Calculate the nth triangular number for a provided bigint.

    Time complexity: O(1)

    Space complexity: O(1)

    Parameters

    • value: bigint

      The number to calculate the triangular number for

    Returns bigint

    The nth triangular number for the provided value

    Math

    triangularNumber(2n); // 3n