• Category

    Calculate the sum of 2 numbers. Meant to be used with Array.prototype.reduce.

    Time complexity: O(1)

    Space complexity: O(1)

    Parameters

    • a: number

      First summand

    • b: number

      Second summand

    Returns number

    The sum of a and b

    Reducers

    const array = [1, 2, 3];

    array.reduce(sum); // 6
  • Category

    Calculate the sum of 2 bigints. Meant to be used with Array.prototype.reduce.

    Time complexity: O(1)

    Space complexity: O(1)

    Parameters

    • a: bigint

      First summand

    • b: bigint

      Second summand

    Returns bigint

    The sum of a and b

    Reducers

    const array = [1n, 2n, 3n];

    array.reduce(sum); // 6n