Added product()

This commit is contained in:
Revar Desmera
2019-05-12 13:32:34 -07:00
parent e8e0d8f3d3
commit ba9b7c5b3b
2 changed files with 26 additions and 0 deletions

View File

@@ -275,6 +275,18 @@ function sum_of_sines(a, sines) =
function deltas(v) = len(v)<2? v : [for (p=pair(v)) p.y-p.x];
// Function: product()
// Description:
// Returns the product of all entries in the given list.
// If passed an array of vectors, returns a vector of products of each part.
// Arguments:
// v = The list to get the product of.
// Example:
// product([2,3,4]); // returns 24.
// product([[1,2,3], [3,4,5], [5,6,7]]); // returns [15, 48, 105]
function product(v, i=0, tot=undef) = i>=len(v)? tot : product(v, i+1, ((tot==undef)? v[i] : is_list(v[i])? vmul(tot,v[i]) : tot*v[i]));
// Function: mean()
// Description:
// Returns the mean of all entries in the given array.