'use strict';

// MODULES //

var pow = require( '@stdlib/math/base/special/pow' );
var PINF = require( '@stdlib/math/constants/float64-pinf' );


// MAIN //

/**
* Computes a chi-square test statistic.
*
* @private
* @param {NumericArray} obs - observation frequencies
* @param {NumericArray} exp - expected frequencies
* @returns {number} test statistic
*/
function testStatistic( obs, exp ) {
	var stat;
	var i;
	stat = 0.0;
	for ( i = 0; i < obs.length; i++ ) {
		if ( exp[ i ] !== 0 ) {
			stat += pow( obs[i] - exp[i], 2 ) / exp[ i ];
		} else {
			if ( obs[ i ] !== 0 ) {
				return PINF;
			}
		}
	}
	return stat;
} // end FUNCTION testStatistic()


// EXPORTS //

module.exports = testStatistic;

'use strict';

// MODULES //

var pow = require( '@stdlib/math/base/special/pow' );
var PINF = require( '@stdlib/math/constants/float64-pinf' );


// MAIN //

/**
* Computes a chi-square test statistic.
*
* @private
* @param {NumericArray} obs - observation frequencies
* @param {NumericArray} exp - expected frequencies
* @returns {number} test statistic
*/
function testStatistic( obs, exp ) {
	var stat;
	var i;
	stat = 0.0;
	for ( i = 0; i < obs.length; i++ ) {
		if ( exp[ i ] !== 0 ) {
			stat += pow( obs[i] - exp[i], 2 ) / exp[ i ];
		} else if ( obs[ i ] !== 0 ) {
			return PINF;
		}
	}
	return stat;
} // end FUNCTION testStatistic()


// EXPORTS //

module.exports = testStatistic;

Fix lint errors