ts-iterable-functions
    Preparing search index...

    Function _reduce

    • Aggregates a sequence into a single result by iteratively combining elements.

      Type Parameters

      • T

        Element type produced by the source iterable.

      • TOut

        Accumulator result type when a distinct seed is supplied.

      Parameters

      • src: Iterable<T>

        Source iterable to be reduced.

      • aggFunc: (prev: TOut, curr: T, idx: number) => TOut

        Combiner invoked with the previous accumulator, current element, and current index.

      • seed: TOut

        Optional initial accumulator; falls back to the first element when omitted.

      Returns TOut

      The final accumulator produced after the reducer runs over the entire sequence.

      If seed is omitted and the source iterable is empty.

      const total = _reduce([1, 2, 3], (prev, curr) => prev + curr);
      console.log(total); // 6

      const product = _reduce([1, 2, 3], (prev, curr) => prev * curr, 1);
      console.log(product); // 6
    • Aggregates a sequence into a single result by iteratively combining elements.

      Type Parameters

      • T

        Element type produced by the source iterable.

      Parameters

      • src: Iterable<T>

        Source iterable to be reduced.

      • aggFunc: (prev: T, curr: T, idx: number) => T

        Combiner invoked with the previous accumulator, current element, and current index.

      Returns T

      The final accumulator produced after the reducer runs over the entire sequence.

      If seed is omitted and the source iterable is empty.

      const total = _reduce([1, 2, 3], (prev, curr) => prev + curr);
      console.log(total); // 6

      const product = _reduce([1, 2, 3], (prev, curr) => prev * curr, 1);
      console.log(product); // 6