nanprod
Computes the product of an array ignoring any non-numeric values.
Installation
$ npm install compute-nanprod
For use in the browser, use browserify.
Usage
var nanprod = ;
nanprod( arr[, accessor] )
Computes the product of an array
ignoring any non-numeric values. For primitive arrays
,
var arr = 1 NaN 2 NaN 1 ;var value = ;// returns 2
For object arrays
, provide an accessor function
for accessing array
values
var arr =14NaN122NaN013;{return d 0 ;}var value = ;// returns 2
Notes
- The product of an
array
containing non-numeric values is equal to the product of an equivalentarray
containing only the numeric values. Hence,
var arr1 = 1 NaN 2 3 NaNarr2 = 1 2 3 ;console;// returns true
- If provided an empty
array
, the method returnsnull
. - If provided an
array
with only non-numeric values, the method returnsNaN
.
Examples
var nanprod = ;var data = 10 ;for var i = 0; i < datalength; i++if i%5 === 0data i = NaN;elsedata i = Math + 1;console;
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2015. Philipp Burckhardt.