Function objReduce

  • Reduces the values of an object into a single value.

    Type Parameters

    • T

      The type of the values in the input object.

    • A

    Parameters

    • object: Record<string, T>

      The object to reduce.

    • callback: ((accum, value, key) => A)

      The function that handles the reduction logic.

        • (accum, value, key): A
        • Parameters

          • accum: A
          • value: T
          • key: string

          Returns A

    • accum: A

      The initial value of the accumulator.

    • getKeys: ((obj) => Iterable<string>) = Object.keys

      The function that retrieves the keys of the object.

        • (obj): Iterable<string>
        • Parameters

          • obj: Record<string, T>

          Returns Iterable<string>

    Returns A

    The final accumulated value.

    Example

    const object = { a: 1, b: 2, c: 3 };
    const callback = (accum, value, key) => accum + value;
    const initialAccum = 0;
    objReduce(object, callback, initialAccum);
    //=> 6

Generated using TypeDoc