@mirei/ts-collections
    Preparing search index...

    Function product

    • Computes the multiplicative aggregate of the values produced for each element in the source iterable.

      Parameters

      • source: Iterable<number>

        The source iterable.

      Returns number

      The product of all projected values.

      Thrown when source is empty.

      source is enumerated exactly once. Supply selector when elements are not already numeric.

      const numbers = [1, 2, 3, 4, 5];
      const result = product(numbers);
      console.log(result); // 120

      const people = [
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      ];
      const ageProduct = product(people, p => p.age);
      console.log(ageProduct); // 750
    • Computes the multiplicative aggregate of the values produced for each element in the source iterable.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • selector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element. Defaults to interpreting the element itself as a number.

      Returns number

      The product of all projected values.

      Thrown when source is empty.

      source is enumerated exactly once. Supply selector when elements are not already numeric.

      const numbers = [1, 2, 3, 4, 5];
      const result = product(numbers);
      console.log(result); // 120

      const people = [
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      ];
      const ageProduct = product(people, p => p.age);
      console.log(ageProduct); // 750