@steelbreeze/pivot
    Preparing search index...

    Function sum

    • Create a callback Function to pass into query that sums numerical values derived by the selector Function.

      Type Parameters

      • TElement

      Parameters

      • selector: Function<TElement, number>

        A callback Function to derive a numerical value for each object in the source data.

      Returns Function<Vector<TElement>, number>

      The following code queries a Cube, returning the average age of players in a squad by country by position:

      const x = dimension(positions, property<Player>('position')); // using the built-in dimension generator matching a property
      const y = dimension(countries, (country: string) => (player: Player) => player.country === country); // using a user-defined generator

      const cube: Cube<Player> = pivot(squad, y, x);

      const result: Matrix<number> = query(cube, sum(age()));

      function age(asAt: Date = new Date()): Function<Player, number> {
      return player => new Date(asAt.getTime() - player.dateOfBirth.getTime()).getUTCFullYear() - 1970;
      }

      See GitHub for a complete example.