Function max

  • Returns the maximum value from an array of numbers.

    Parameters

    • arr: number[]

      The array of numbers.

    Returns number

    The maximum value from the array.

    Throws

    Throws an error if the array length is 0.

    Example

    const numbers = [1, 3, 2, 5, 4];
    const maxNumber = max(numbers);
    console.log(maxNumber);
    // Output: 5
  • Returns the maximum value from an array of bigints.

    Parameters

    • arr: bigint[]

      The array of bigints.

    Returns bigint

    The maximum value from the array.

    Throws

    Throws an error if the array length is 0.

    Example

    const bigints = [BigInt(1), BigInt(3), BigInt(2), BigInt(5), BigInt(4)];
    const maxBigInt = max(bigints);
    console.log(maxBigInt);
    // Output: 5n
  • Returns the maximum value from an array using a custom numerical implementation.

    Type Parameters

    • T

      The type of the elements in the array.

    Parameters

    • arr: T[]

      The array of elements.

    • Optional numerical: Numerical<T>

      The numerical implementation to use.

    Returns T

    The maximum value from the array.

    Throws

    Throws an error if the array length is 0 or if no appropriate numerical implementation is provided.

    Example

    const array = [1, 3, 2, 5, 4];
    const maxElement = max(array, new NumericalNumber());
    console.log(maxElement);
    // Output: 5

Generated using TypeDoc