Skip to content

hville/sum-product

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sum-product

UsageTestLicense

Simple and small standalone function to calculate the sum of the product of array items. sumProduct([0,1], [2,3], [4,5]) // 0*2*4 + 1*3*5 = 15

Uses a modified Kahan sum to reduce floating point errors.

Usage

The function takes any number of arrays.

var sumProduct = require('sum-product')
var result = sumProduct([0,1], [2,3], [4,5]) //  0*2*4 + 1*3*5 = 15
result = sumProduct() //  ==>0
result = sumProduct([]) //  ==>0
result = sumProduct([a]) //  ==>NaN

License

Released under the MIT License

About

classic spreadsheet sum of array item products

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published