'use strict';

// MODULES //

var matrix = require( './matrix.js' );


// MAIN //

/**
* Calculate weighted average of two matrices.
*
* @param {Matrix} A - first matrix
* @param {Matrix} B - second matrix
* @param {PositiveInteger} weight - relative weight of matrix A
* @returns {Matrix} averaged matrix
*/
function avgMatrix( A, B, weight ) {
	var propA;
	var propB;
	var nrow;
	var ncol;
	var val;
	var C;
	var i;
	var j;

	nrow = A.shape[ 0 ];
	ncol = A.shape[ 1 ];
	C = matrix( [ nrow, ncol ] );
	propA = ( weight - 1.0 ) / weight;
	propB = 1.0 / weight;

	for ( i = 0; i < nrow; i++ ) {
		for ( j = 0; j < ncol; j++ ) {
			val = propA * A.get( i, j ) + propB * B.get( i, j );
			C.set( i, j, val );
		}
	}
	return C;
} // end FUNCTION avgMatrix()


// EXPORTS //

module.exports = avgMatrix;

'use strict';

// MODULES //

var matrix = require( './matrix.js' );


// MAIN //

/**
* Calculate weighted average of two matrices.
*
* @param {Matrix} A - first matrix
* @param {Matrix} B - second matrix
* @param {PositiveInteger} weight - relative weight of matrix A
* @returns {Matrix} averaged matrix
*/
function avgMatrix( A, B, weight ) {
	var propA;
	var propB;
	var nrow;
	var ncol;
	var val;
	var C;
	var i;
	var j;

	nrow = A.shape[ 0 ];
	ncol = A.shape[ 1 ];
	C = matrix( [ nrow, ncol ] );
	propA = ( weight - 1.0 ) / weight;
	propB = 1.0 / weight;

	for ( i = 0; i < nrow; i++ ) {
		for ( j = 0; j < ncol; j++ ) {
			val = (propA * A.get(i, j)) + (propB * B.get(i, j));
			C.set( i, j, val );
		}
	}
	return C;
} // end FUNCTION avgMatrix()


// EXPORTS //

module.exports = avgMatrix;

Add parentheses to clarify operations
Add parentheses to clarify operations
