deno.land / x / simplestatistic@v7.7.1 / src / product.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/** * The [product](https://en.wikipedia.org/wiki/Product_(mathematics)) of an array * is the result of multiplying all numbers together, starting using one as the multiplicative identity. * * This runs in `O(n)`, linear time, with respect to the length of the array. * * @param {Array<number>} x input * @return {number} product of all input numbers * @example * product([1, 2, 3, 4]); // => 24 */function product(x) { let value = 1; for (let i = 0; i < x.length; i++) { value *= x[i]; } return value;}
export default product;
simplestatistic

Version Info

Tagged at
2 years ago