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.


    The result of calling reducer on each item.


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



    Type Parameters

    • T


    • 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