ts-data-forge
    Preparing search index...
    • Returns an array of successively reduced values from an array.

      Type Parameters

      • const Ar extends readonly unknown[]
      • S

      Parameters

      • array: Ar
      • reducer: (accumulator: S, currentValue: Ar[number], currentIndex: ArrayIndex<Ar>) => S
      • init: S

      Returns readonly [S, S]

      const changes = [5, -2, 3] as const;

      const runningTotals = Arr.scan(changes, (total, change) => total + change, 0);
      const runningTotalsFromCurried = Arr.scan(
      (total: number, change: number) => total + change,
      10,
      )([-5, 15]);

      const expectedTotals = [0, 5, 3, 6] as const;
      const expectedCurriedTotals = [10, 5, 20] as const;

      assert.deepStrictEqual(runningTotals, expectedTotals);
      assert.deepStrictEqual(runningTotalsFromCurried, expectedCurriedTotals);
    • Returns an array of successively reduced values from an array.

      Type Parameters

      • E
      • S

      Parameters

      • reducer: (accumulator: S, currentValue: E, currentIndex: Uint32) => S
      • init: S

      Returns (array: readonly E[]) => readonly [S, S]

      const changes = [5, -2, 3] as const;

      const runningTotals = Arr.scan(changes, (total, change) => total + change, 0);
      const runningTotalsFromCurried = Arr.scan(
      (total: number, change: number) => total + change,
      10,
      )([-5, 15]);

      const expectedTotals = [0, 5, 3, 6] as const;
      const expectedCurriedTotals = [10, 5, 20] as const;

      assert.deepStrictEqual(runningTotals, expectedTotals);
      assert.deepStrictEqual(runningTotalsFromCurried, expectedCurriedTotals);