Skip to content

Provides a method to compute a maximum value incrementally.

License

Notifications You must be signed in to change notification settings

compute-io/incrmax

Repository files navigation

incrmax

NPM version Build Status Coverage Status Dependencies

Provides a method to compute a maximum value incrementally.

Installation

$ npm install compute-incrmax

For use in the browser, use browserify.

Usage

var incrmax = require( 'compute-incrmax' );

incrmax()

Returns an initialized method to compute a maximum value incrementally.

var max = incrmax();

max( [value] )

If provided a value, the method updates and returns the updated max. If not provided a value, the method returns the current max.

max( 2 );

console.log( max( 1 ) );
// returns 2

max( 3 );

console.log( max() );
// returns 3

Note: if values have not yet been provided to max(), max() returns null.

Examples

var incrmax = require( 'compute-incrmax' );

// Initialize a method to calculate the max incrementally:
var max = incrmax();

// Simulate some data...
for ( var i = 0; i < 1000; i++ ) {
	max( Math.random() * 100 );
}

console.log( max() );

To run the example code from the top-level application directory,

$ node ./examples/index.js

Notes

The use case for this module differs from the conventional vector implementation and the stream implementation. Namely, this module decouples the act of updating the max from the act of consuming the max.

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

MIT license.

Copyright

Copyright © 2014-2015. The Compute.io Authors.

About

Provides a method to compute a maximum value incrementally.

Resources

License

Stars

Watchers

Forks

Packages

No packages published