function check( ndims, shape, d, arr, flg ) {
	var len;
	var v;
	var i;

	// Get the size of the current dimension:
	len = shape[ d ];

	// Ensure that each array element is an array of the same size:
	for ( i = 0; i < arr.length; i++ ) {
		v = arr[ i ];

		// If the array element is not an array or is not the same size, we have found an inconsistent dimension:
		if ( !isArrayLikeObject( v ) || v.length !== len ) {
			// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:
			return d;
		}
		// Recursively examine nested elements:
		if ( flg ) {
			v = check( ndims, shape, d+1, v, d+1 < ndims-1 );
			if ( v < ndims ) {
				// Propagate the number of consistent dimensions up the recursion chain...
				return v;
			}
		}
	}
	return ndims;
}
Recursively verifies that all nested arrays have consistent dimensions.

@private
@param {PositiveInteger} ndims - number of dimensions
@param {Array} shape - shape array
@param {NonNegativeInteger} d - dimension
@param {ArrayLikeObject} arr - array element to verify
@param {boolean} flg - boolean indicating whether to continue recursing
@returns {NonNegativeInteger} number of consistent dimensions