Function prod

  • Computes the product of a number array.

    Parameters

    • array: number[]

      The array of numbers.

    Returns number

    The product of all numbers in the array.

    Example

    prod([3, 4]);  // Returns 12
    
  • Computes the product of a bigint array.

    Parameters

    • array: bigint[]

      The array of bigints.

    Returns bigint

    The product of all bigints in the array.

    Example

    prod([3n, 4n]);  // Returns 12n
    
  • Computes the product of an array of numeric type T.

    Type Parameters

    • T

      The numeric type of the elements in the array. T is inferred and doesn't need to be supplied manually.

    Parameters

    • array: T[]

      The array of elements.

    • Optional numerical: Numerical<T>

      (optional) An instance of Numerical interface for the numeric type T.

      • If not provided, it defaults to NumericalNumber if the array is of type number[], or to NumericalBigInt if the array is of type bigint[].
      • If array is neither number[] nor bigint[], a Numerical instance must be provided.

    Returns T

    The product of all elements in the array.

    Throws

    If the array's type is neither number[] nor bigint[], and no Numerical instance was provided.

    Example

    prod([3, 4]);                  // Returns 12
    prod([3n, 4n]); // Returns 12n
    prod([3, 4], new Numerical()); // Where Numerical() is an implementation for type T.

Generated using TypeDoc