test/utils/deepcloseto.js
/**
* FUNCTION: deepCloseTo( x, y, eps[, options] )
*	Validates if two input values `x` and `y` are equal to within an acceptable tolerance using a recursive algorithm. For objects, properties having numeric values are considered acceptably equal if the values differ by less than an allowable tolerance (epsilon).
*
* @param {*} x - input value
* @param {*} y - input value
* @param {Number} eps - epsilon
* @param {Object} [options] - function options
* @param {Boolean} [options.strict=true] - boolean indicating whether to require strict equality for non-numeric values
* @returns {Boolean} boolean indicating whether the inputs are recursively equal to within an acceptable tolerance
*/
deepCloseTo( x, y, eps[, options] )
Validates if two input values `x` and `y` are equal to within an acceptable tolerance using a recursive algorithm. For objects, properties having numeric values are considered acceptably equal if the values differ by less than an allowable tolerance (epsilon).
deepCloseTo ( x y eps [ options ] ) Validates if two input values ` x ` and ` y ` are equal to within an acceptable tolerance using a recursive algorithm . For objects properties having numeric values are considered acceptably equal if the values differ by less than an allowable tolerance ( epsilon ) .
function deepCloseTo( x, y, eps, options ) {
	var type = typeof x,
		opts,
		keys,
		bool,
		key,
		len,
		i;
	if ( arguments.length > 3 ) {
		opts = options;
	} else {
		opts = {};
	}
	if ( x === y ) {
		return true;
	}
	else if ( type === 'number' && typeof y === 'number' ) {
		if ( x !== x && y !== y ) {
			return true;
		}
		return closeTo( x, y, eps );
	}
	else if ( x instanceof Date && y instanceof Date ) {
		return closeTo( x.getTime(), y.getTime(), eps );
	}
	else if ( type !== 'object' && typeof y !== 'object' ) {
		return ( opts.strict === false ) ? x == y : false;
	}
	keys = Object.keys( x );
	len = keys.length;
	if ( Object.keys( y ).length !== len ) {
		return false;
	}
	for ( i = 0; i < len; i++ ) {
		key = keys[ i ];
		bool = deepCloseTo( x[ key ], y[ key ], eps );
		if ( bool === false ) {
			return false;
		}
	}
	return true;
} 
function deepCloseTo ( x , y , eps , options ) { var type = typeof x , opts , keys , bool , key , len , i ; if ( arguments . length > 3 ) { opts = options ; } else { opts = { } ; } if ( x === y ) { return true ; } else if ( type === 'number' && typeof y === 'number' ) { if ( x !== x && y !== y ) { return true ; } return closeTo ( x , y , eps ) ; } else if ( x instanceof Date && y instanceof Date ) { return closeTo ( x . getTime ( ) , y . getTime ( ) , eps ) ; } else if ( type !== 'object' && typeof y !== 'object' ) { return ( opts . strict === false ) ? x == y : false ; } keys = Object . keys ( x ) ; len = keys . length ; if ( Object . keys ( y ) . length !== len ) { return false ; } for ( i = 0 ; i < len ; i ++ ) { key = keys [ i ] ; bool = deepCloseTo ( x [ key ] , y [ key ] , eps ) ; if ( bool === false ) { return false ; } } return true ; }
FUNCTION: deepCloseTo( x, y, eps[, options] )
Validates if two input values `x` and `y` are equal to within an acceptable tolerance using a recursive algorithm.
FUNCTION : deepCloseTo ( x y eps [ options ] ) Validates if two input values ` x ` and ` y ` are equal to within an acceptable tolerance using a recursive algorithm .
/* jshint eqeqeq:true */ // All identical values are equivalent... // If both values are numbers, compare them... // Handle case where both values are NaN... // Handle dates... // Handle case where both values are non-objects and failed equality... /* jshint eqeqeq:false */ /* jshint eqeqeq:true */ // end FUNCTION deepCloseTo()