Package Exports
- compute-gt
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (compute-gt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Greater Than
Computes an element-wise comparison (greater than) of an array.
Installation
$ npm install compute-gt
For use in the browser, use browserify.
Usage
To use the module,
var gt = require( 'compute-gt' );
gt( arr, x )
Computes an element-wise comparison (greater than) for each input array
element. x
may either be an array
of equal length or a single value (number
or string
).
The function returns an array
with length equal to that of the input array
. Each output array
element is either 0
or 1
. A value of 1
means that an element is greater than a compared value and 0
means that an element is not greater than a compared value.
var arr = [ 5, 3, 8, 3, 2 ],
out;
// Single comparison value:
out = gt( arr, 4 );
// returns [ 1, 0, 1, 0, 0 ]
// Array of comparison values:
out = gt( arr, [ 6, 2, 6, 7, 3 ] );
// returns [ 0, 1, 1, 0, 0 ]
Examples
var gt = require( 'compute-gt' ),
sum = require( 'compute-sum' );
// Simulate some data...
var data = new Array( 100 );
for ( var i = 0; i < data.length; i++ ) {
data[ i ] = Math.round( Math.random()*100 );
}
var out = gt( data, 50 );
// Count the number of values exceeding 50...
var count = sum( out );
console.log( 'Total: %d', count );
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 © 2014. Athan Reines.