function recurseLexicographic( x, ndims, shape, dim, out, stride, offset ) {
	var FLG;
	var S;
	var d;
	var i;

	// Check whether we've reached the last dimension:
	d = dim + 1;
	FLG = ( d === ndims );

	S = shape[ dim ];
	for ( i = 0; i < S; i++ ) {
		if ( FLG ) {
			out[ offset ] = x[ i ];
			offset += stride;
		} else {
			offset = recurseLexicographic( x[ i ], ndims, shape, d, out, stride, offset ); // eslint-disable-line max-len
		}
	}
	return offset;
}
Recursively flattens an array in lexicographic order.

@private
@param {Array} x - array to flatten
@param {NonNegativeInteger} ndims - number of dimensions in the input array
@param {NonNegativeIntegerArray} shape - shape of the input array
@param {NonNegativeInteger} dim - dimension index
@param {Collection} out - output array
@param {integer} stride - output array stride
@param {NonNegativeInteger} offset - output array offset
@returns {NonNegativeInteger} offset for next output array element