Function reduce

  • Returns the result of applying the reducer function to each element of the source.

    Type Parameters

    • T

      Type of items in the source.

    • O

      Type of the result.

    Parameters

    • reducerFunction: ReduceFunction<T, O>

      Reducer function to apply to each element.

    • initialValue: ValueOrFactory<O>

      Initial value or factory function to use as the first argument to the reducer function.

    Returns CollectorFunction<T, O>

    Collector that returns the result of applying the reducer function to each element of the source.

    const result = reduce<number, number>((prev, curr) => prev + curr, 0)([1, 2, 3]);
    console.log(result); // 6