You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A frequent scenario is where you have two arrays (or filter runs) of numbers where you want each element from one array to be multiplied by the corresponding element from the other array, and the resulting product to be summed. This is equivalent in a spreadsheet to multiplying two columns by each other and summing the result.
If there's a way to do this with the current set of functions, then I apologize and would be eager to see how to make that work. In the mean time, I came up with the following code below. Note that I don't have it doing the regression like the Sum function does -- I'm not sure that that ability applies in this case.
Thank you
Mark
function Crosssum(a,b) {
if (a instanceof Array && b instanceof Array ) {
var n = 0;
for (var i = 0; i < a.length; ++i) n += (a[i]*b[i]);
return n;
}
return Coerce.ToNum(a,this);
}
exports.crosssum = Crosssum ;
The text was updated successfully, but these errors were encountered:
Marxsal
changed the title
Cross-sum : Functioning for summing the product of two arrays.
Cross-sum : Function for summing the product of two arrays.
Apr 28, 2018
A frequent scenario is where you have two arrays (or filter runs) of numbers where you want each element from one array to be multiplied by the corresponding element from the other array, and the resulting product to be summed. This is equivalent in a spreadsheet to multiplying two columns by each other and summing the result.
If there's a way to do this with the current set of functions, then I apologize and would be eager to see how to make that work. In the mean time, I came up with the following code below. Note that I don't have it doing the regression like the Sum function does -- I'm not sure that that ability applies in this case.
Thank you
Mark
function Crosssum(a,b) {
if (a instanceof Array && b instanceof Array ) {
var n = 0;
for (var i = 0; i < a.length; ++i) n += (a[i]*b[i]);
return n;
}
return Coerce.ToNum(a,this);
}
exports.crosssum = Crosssum ;
The text was updated successfully, but these errors were encountered: