Skip to main content

Function: product()

product(iterable: IterableResolvable<number>): number

Consumes the iterable and returns the product of all the elements. If the iterable is empty, it returns 1.

Parameters

ParameterTypeDescription
iterableIterableResolvable<number>An iterator to calculate the product of.

Returns

number

The product of the elements in the input iterator.

Example

import { product } from '@sapphire/iterator-utilities';

const iterable = [1, 2, 3, 4, 5];
console.log(product(iterable));
// Output: 120

const iterable = [1, 2, 3, 4, 5, 0];
console.log(product(iterable));
// Output: 0

Defined in

projects/utilities/packages/iterator-utilities/src/lib/product.ts:24