Function reduce

  • Applies a reducer function on each element of the iterable, in order, passing the return value from the operation on the previous element. The final result of running the reducer across all elements of the iterable is a single value.

    Returns

    The result of calling reducer on each item.

    Example

    reduce([1, 2, 3, 4, 5], (x, y) => x + y, 0)
    // 15

    See

    Array.reduce()

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T>

      The collection to reduce.

    • reducer: ((prev: T, value: T, index: any) => T)

      A reducer function that will be called per item.

        • (prev: T, value: T, index: any): T
        • Parameters

          • prev: T
          • value: T
          • index: any

          Returns T

    • Optional initial: any

      Optional initial value (defaults to the first element in the iterable).

    Returns any

Generated using TypeDoc